A decentralized music tracking and discovery platform built on AT Protocol 🎵

[api] return files and directories (dropbox/googledrive)

[api] return files and directories (dropbox/googledrive)

[api] return files and directories (dropbox/googledrive)

[api] return files and directories (dropbox/googledrive)

[api] return files and directories (dropbox/googledrive)

[api] return files and directories (dropbox/googledrive)

+123 -34
+53 -17
apps/api/src/xrpc/app/rocksky/dropbox/getFiles.ts
··· 5 5 import { Effect, pipe } from "effect"; 6 6 import { Server } from "lexicon"; 7 7 import { QueryParams } from "lexicon/types/app/rocksky/dropbox/getFiles"; 8 + import _ from "lodash"; 8 9 import tables from "schema"; 9 10 10 11 export default function (server: Server, ctx: Context) { ··· 44 45 return Effect.tryPromise({ 45 46 try: async () => { 46 47 const parentAlias = alias(tables.dropboxDirectories, "parent"); 47 - return ctx.db 48 - .select() 49 - .from(tables.dropboxDirectories) 50 - .leftJoin( 51 - tables.dropbox, 52 - eq(tables.dropbox.id, tables.dropboxDirectories.dropboxId) 53 - ) 54 - .leftJoin(tables.users, eq(tables.dropbox.userId, tables.users.id)) 55 - .leftJoin( 56 - parentAlias, 57 - eq(parentAlias.id, tables.dropboxDirectories.parentId) 58 - ) 59 - .where(and(eq(tables.users.did, did), eq(parentAlias.path, params.at))) 60 - .execute(); 48 + return Promise.all([ 49 + ctx.db 50 + .select() 51 + .from(tables.dropboxDirectories) 52 + .leftJoin( 53 + tables.dropbox, 54 + eq(tables.dropbox.id, tables.dropboxDirectories.dropboxId) 55 + ) 56 + .leftJoin(tables.users, eq(tables.dropbox.userId, tables.users.id)) 57 + .leftJoin( 58 + parentAlias, 59 + eq(parentAlias.id, tables.dropboxDirectories.parentId) 60 + ) 61 + .where( 62 + and( 63 + eq(tables.users.did, did), 64 + eq(parentAlias.path, _.get(params, "at", "/Music")) 65 + ) 66 + ) 67 + .execute(), 68 + ctx.db 69 + .select() 70 + .from(tables.dropboxPaths) 71 + .leftJoin( 72 + tables.dropboxDirectories, 73 + eq(tables.dropboxDirectories.id, tables.dropboxPaths.directoryId) 74 + ) 75 + .leftJoin( 76 + tables.dropbox, 77 + eq(tables.dropbox.id, tables.dropboxPaths.dropboxId) 78 + ) 79 + .leftJoin(tables.users, eq(tables.dropbox.userId, tables.users.id)) 80 + .where( 81 + and( 82 + eq(tables.users.did, did), 83 + eq(tables.dropboxDirectories.path, _.get(params, "at", "/Music")) 84 + ) 85 + ) 86 + .execute(), 87 + ]); 61 88 }, 62 89 catch: (error) => { 63 90 console.error("Failed to retrieve files:", error); ··· 68 95 69 96 const presentation = (data) => { 70 97 return Effect.sync(() => ({ 71 - files: data.map((item) => ({ 98 + directories: data[0].map((item) => ({ 72 99 id: item.dropbox_directories.id, 73 100 name: item.dropbox_directories.name, 74 101 fileId: item.dropbox_directories.fileId, 75 102 path: item.dropbox_directories.path, 76 103 parentId: item.dropbox_directories.parentId, 77 - createdAt: item.dropbox_directories.xata_createdat, 78 - updatedAt: item.dropbox_directories.xata_updatedat, 104 + createdAt: item.dropbox_directories.createdAt.toISOString(), 105 + updatedAt: item.dropbox_directories.updatedAt.toISOString(), 106 + })), 107 + files: data[1].map((item) => ({ 108 + id: item.dropbox_paths.id, 109 + name: item.dropbox_paths.name, 110 + fileId: item.dropbox_paths.fileId, 111 + directoryId: item.dropbox_paths.directoryId, 112 + trackId: item.dropbox_paths.trackId, 113 + createdAt: item.dropbox_paths.createdAt.toISOString(), 114 + updatedAt: item.dropbox_paths.updatedAt.toISOString(), 79 115 })), 80 116 })); 81 117 };
+70 -17
apps/api/src/xrpc/app/rocksky/googledrive/getFiles.ts
··· 4 4 import { Effect, pipe } from "effect"; 5 5 import { Server } from "lexicon"; 6 6 import { QueryParams } from "lexicon/types/app/rocksky/googledrive/getFiles"; 7 + import _ from "lodash"; 7 8 import tables from "schema"; 8 9 9 10 export default function (server: Server, ctx: Context) { ··· 43 44 return Effect.tryPromise({ 44 45 try: async () => { 45 46 const parentAlias = alias(tables.googleDriveDirectories, "parent"); 46 - return ctx.db 47 - .select() 48 - .from(tables.googleDriveDirectories) 49 - .leftJoin( 50 - tables.googleDrive, 51 - eq(tables.googleDrive.id, tables.googleDriveDirectories.googleDriveId) 52 - ) 53 - .leftJoin(tables.users, eq(tables.googleDrive.userId, tables.users.id)) 54 - .leftJoin( 55 - parentAlias, 56 - eq(parentAlias.id, tables.googleDriveDirectories.parentId) 57 - ) 58 - .where(and(eq(tables.users.did, did), eq(parentAlias.path, params.at))) 59 - .execute(); 47 + return Promise.all([ 48 + ctx.db 49 + .select() 50 + .from(tables.googleDriveDirectories) 51 + .leftJoin( 52 + tables.googleDrive, 53 + eq( 54 + tables.googleDrive.id, 55 + tables.googleDriveDirectories.googleDriveId 56 + ) 57 + ) 58 + .leftJoin( 59 + tables.users, 60 + eq(tables.googleDrive.userId, tables.users.id) 61 + ) 62 + .leftJoin( 63 + parentAlias, 64 + eq(parentAlias.id, tables.googleDriveDirectories.parentId) 65 + ) 66 + .where( 67 + and( 68 + eq(tables.users.did, did), 69 + eq(parentAlias.path, _.get(params, "at", "/Music")) 70 + ) 71 + ) 72 + .execute(), 73 + ctx.db 74 + .select() 75 + .from(tables.googleDrivePaths) 76 + .leftJoin( 77 + tables.googleDriveDirectories, 78 + eq( 79 + tables.googleDrivePaths.directoryId, 80 + tables.googleDriveDirectories.id 81 + ) 82 + ) 83 + .leftJoin( 84 + tables.googleDrive, 85 + eq(tables.googleDrive.id, tables.googleDrivePaths.googleDriveId) 86 + ) 87 + .leftJoin( 88 + tables.users, 89 + eq(tables.googleDrive.userId, tables.users.id) 90 + ) 91 + .where( 92 + and( 93 + eq(tables.users.did, did), 94 + eq( 95 + tables.googleDriveDirectories.path, 96 + _.get(params, "at", "/Music") 97 + ) 98 + ) 99 + ) 100 + .execute(), 101 + ]); 60 102 }, 61 103 catch: (error) => { 62 104 console.error("Failed to retrieve files:", error); ··· 66 108 }; 67 109 68 110 const presentation = (data) => { 111 + console.log(data[0]); 112 + console.log(data[1]); 69 113 return Effect.sync(() => ({ 70 - files: data.map((item) => ({ 114 + directories: data[0].map((item) => ({ 71 115 id: item.google_drive_directories.id, 72 116 name: item.google_drive_directories.name, 73 117 fileId: item.google_drive_directories.fileId, 74 118 path: item.google_drive_directories.path, 75 119 parentId: item.google_drive_directories.parentId, 76 - createdAt: item.google_drive_directories.xata_createdat, 77 - updatedAt: item.google_drive_directories.xata_updatedat, 120 + createdAt: item.google_drive_directories.createdAt.toISOString(), 121 + updatedAt: item.google_drive_directories.updatedAt.toISOString(), 122 + })), 123 + files: data[1].map((item) => ({ 124 + id: item.google_drive_paths.id, 125 + name: item.google_drive_paths.name, 126 + fileId: item.google_drive_paths.fileId, 127 + directoryId: item.google_drive_paths.directoryId, 128 + trackId: item.google_drive_paths.trackId, 129 + createdAt: item.google_drive_paths.createdAt.toISOString(), 130 + updatedAt: item.google_drive_paths.updatedAt.toISOString(), 78 131 })), 79 132 })); 80 133 };