diff options
| author | Pitu <[email protected]> | 2019-03-02 22:07:24 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2019-03-02 22:07:24 +0900 |
| commit | ce76a8ec7ba2084ab75fb901933b3d4d84505032 (patch) | |
| tree | 8b883904e8e41c85ae0f1c7de74aebb6e050a831 /src/api/routes/files/filesGET.js | |
| parent | Fix token (diff) | |
| download | host.fuwn.me-ce76a8ec7ba2084ab75fb901933b3d4d84505032.tar.xz host.fuwn.me-ce76a8ec7ba2084ab75fb901933b3d4d84505032.zip | |
Be able to add a file to multiple albums
Diffstat (limited to 'src/api/routes/files/filesGET.js')
| -rw-r--r-- | src/api/routes/files/filesGET.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/api/routes/files/filesGET.js b/src/api/routes/files/filesGET.js index b41996b..ce288ff 100644 --- a/src/api/routes/files/filesGET.js +++ b/src/api/routes/files/filesGET.js @@ -14,6 +14,21 @@ class filesGET extends Route { .where('userId', user.id) .orderBy('id', 'desc'); + for (const file of files) { + file.albums = []; + const albumFiles = await db.table('albumsFiles') + .where('fileId', file.id); + if (!albumFiles.length) continue; + + for (const albumFile of albumFiles) { + const album = await db.table('albums') + .where('id', albumFile.albumId) + .select('id', 'name') + .first(); + if (!album) continue; + file.albums.push(album); + } + } /* For each file, create the public link to be able to display the file */ |