aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes
diff options
context:
space:
mode:
authorPitu <[email protected]>2021-06-08 00:33:01 +0900
committerPitu <[email protected]>2021-06-08 00:33:01 +0900
commit9b28e56e09ef31052935c00c830ceafd481b94f3 (patch)
tree3e01309b801890765b3f5e06f962399f237725a8 /src/api/routes
parentchore: simplify dev commands (diff)
downloadhost.fuwn.me-9b28e56e09ef31052935c00c830ceafd481b94f3.tar.xz
host.fuwn.me-9b28e56e09ef31052935c00c830ceafd481b94f3.zip
chore: get host from req instead of config
Diffstat (limited to 'src/api/routes')
-rw-r--r--src/api/routes/admin/fileGET.js2
-rw-r--r--src/api/routes/admin/userGET.js2
-rw-r--r--src/api/routes/albums/albumFullGET.js2
-rw-r--r--src/api/routes/albums/albumGET.js2
-rw-r--r--src/api/routes/albums/albumsGET.js2
-rw-r--r--src/api/routes/albums/link/linkPOST.js10
-rw-r--r--src/api/routes/files/fileGET.js2
-rw-r--r--src/api/routes/files/filesGET.js2
-rw-r--r--src/api/routes/search/searchGET.js2
-rw-r--r--src/api/routes/service/configGET.js1
-rw-r--r--src/api/routes/uploads/uploadPOST.js4
11 files changed, 10 insertions, 21 deletions
diff --git a/src/api/routes/admin/fileGET.js b/src/api/routes/admin/fileGET.js
index 9605da4..72b96f1 100644
--- a/src/api/routes/admin/fileGET.js
+++ b/src/api/routes/admin/fileGET.js
@@ -15,7 +15,7 @@ class filesGET extends Route {
.select('id', 'username', 'enabled', 'createdAt', 'editedAt', 'apiKeyEditedAt', 'isAdmin')
.where({ id: file.userId })
.first();
- file = Util.constructFilePublicLink(file);
+ file = Util.constructFilePublicLink(req, file);
// Additional relevant data
const filesFromUser = await db.table('files').where({ userId: user.id }).select('id');
diff --git a/src/api/routes/admin/userGET.js b/src/api/routes/admin/userGET.js
index 430dfd7..bf4f912 100644
--- a/src/api/routes/admin/userGET.js
+++ b/src/api/routes/admin/userGET.js
@@ -37,7 +37,7 @@ class usersGET extends Route {
}
for (let file of files) {
- file = Util.constructFilePublicLink(file);
+ file = Util.constructFilePublicLink(req, file);
}
return res.json({
diff --git a/src/api/routes/albums/albumFullGET.js b/src/api/routes/albums/albumFullGET.js
index d25fe15..32c7326 100644
--- a/src/api/routes/albums/albumFullGET.js
+++ b/src/api/routes/albums/albumFullGET.js
@@ -43,7 +43,7 @@ class albumGET extends Route {
// eslint-disable-next-line no-restricted-syntax
for (let file of files) {
- file = Util.constructFilePublicLink(file);
+ file = Util.constructFilePublicLink(req, file);
}
return res.json({
diff --git a/src/api/routes/albums/albumGET.js b/src/api/routes/albums/albumGET.js
index 4ac7089..e121a31 100644
--- a/src/api/routes/albums/albumGET.js
+++ b/src/api/routes/albums/albumGET.js
@@ -44,7 +44,7 @@ class albumGET extends Route {
}
for (let file of files) {
- file = Util.constructFilePublicLink(file);
+ file = Util.constructFilePublicLink(req, file);
}
// Add 1 more view to the link
diff --git a/src/api/routes/albums/albumsGET.js b/src/api/routes/albums/albumsGET.js
index 3c18d8f..98cc82e 100644
--- a/src/api/routes/albums/albumsGET.js
+++ b/src/api/routes/albums/albumsGET.js
@@ -37,7 +37,7 @@ class albumsGET extends Route {
// Fetch thumbnails and stuff
for (let file of files) {
- file = Util.constructFilePublicLink(file);
+ file = Util.constructFilePublicLink(req, file);
}
album.fileCount = fileCount[0].count;
diff --git a/src/api/routes/albums/link/linkPOST.js b/src/api/routes/albums/link/linkPOST.js
index 42eac58..7bc8051 100644
--- a/src/api/routes/albums/link/linkPOST.js
+++ b/src/api/routes/albums/link/linkPOST.js
@@ -20,16 +20,6 @@ class linkPOST extends Route {
.first();
if (!exists) return res.status(400).json({ message: 'Album doesn\t exist' });
- /*
- Count the amount of links created for that album already and error out if max was reached
- */
- const count = await db
- .table('links')
- .where('albumId', albumId)
- .count({ count: 'id' })
- .first();
- if (count >= parseInt(process.env.MAX_LINKS_PER_ALBUM, 10)) return res.status(400).json({ message: 'Maximum links per album reached' });
-
let { identifier } = req.body;
if (identifier) {
if (!user.isAdmin) return res.status(401).json({ message: 'Only administrators can create custom links' });
diff --git a/src/api/routes/files/fileGET.js b/src/api/routes/files/fileGET.js
index 9ec6f22..2e6f0b8 100644
--- a/src/api/routes/files/fileGET.js
+++ b/src/api/routes/files/fileGET.js
@@ -16,7 +16,7 @@ class fileGET extends Route {
let file = await db.table('files').where({ id, userId: user.id }).first();
if (!file) return res.status(400).json({ message: 'The file doesn\'t exist or doesn\'t belong to the user' });
- file = Util.constructFilePublicLink(file);
+ file = Util.constructFilePublicLink(req, file);
/*
Fetch the albums
diff --git a/src/api/routes/files/filesGET.js b/src/api/routes/files/filesGET.js
index 9e90633..20ccbc5 100644
--- a/src/api/routes/files/filesGET.js
+++ b/src/api/routes/files/filesGET.js
@@ -30,7 +30,7 @@ class filesGET extends Route {
// For each file, create the public link to be able to display the file
for (let file of files) {
- file = Util.constructFilePublicLink(file);
+ file = Util.constructFilePublicLink(req, file);
}
return res.json({
diff --git a/src/api/routes/search/searchGET.js b/src/api/routes/search/searchGET.js
index 187fcab..3cfcfef 100644
--- a/src/api/routes/search/searchGET.js
+++ b/src/api/routes/search/searchGET.js
@@ -53,7 +53,7 @@ class configGET extends Route {
// For each file, create the public link to be able to display the file
for (let file of files) {
- file = Util.constructFilePublicLink(file);
+ file = Util.constructFilePublicLink(req, file);
}
return res.json({
diff --git a/src/api/routes/service/configGET.js b/src/api/routes/service/configGET.js
index bc91a7e..291f0a4 100644
--- a/src/api/routes/service/configGET.js
+++ b/src/api/routes/service/configGET.js
@@ -11,7 +11,6 @@ class configGET extends Route {
config: {
serviceName: process.env.SERVICE_NAME,
uploadFolder: process.env.UPLOAD_FOLDER,
- linksPerAlbum: parseInt(process.env.MAX_LINKS_PER_ALBUM, 10),
maxUploadSize: parseInt(process.env.MAX_SIZE, 10),
filenameLength: parseInt(process.env.GENERATED_FILENAME_LENGTH, 10),
albumLinkLength: parseInt(process.env.GENERATED_ALBUM_LENGTH, 10),
diff --git a/src/api/routes/uploads/uploadPOST.js b/src/api/routes/uploads/uploadPOST.js
index a0dba27..7386490 100644
--- a/src/api/routes/uploads/uploadPOST.js
+++ b/src/api/routes/uploads/uploadPOST.js
@@ -282,8 +282,8 @@ class uploadPOST extends Route {
if (albumId) await Util.saveFileToAlbum(db, albumId, result.id);
- result.file = Util.constructFilePublicLink(result.file);
- result.deleteUrl = `${process.env.DOMAIN}/api/file/${result.id[0]}`;
+ result.file = Util.constructFilePublicLink(req, result.file);
+ result.deleteUrl = `${Util.getHost(req)}/api/file/${result.id[0]}`;
return res.status(201).send({
message: 'Sucessfully uploaded the file.',