-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ubtl
committed
Feb 15, 2024
1 parent
6bb1759
commit d634ef8
Showing
26,438 changed files
with
2,415,436 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const getResponse = require('../util/getResponse'); | ||
|
||
const badRequest = (req, res) => { | ||
return res.json(getResponse(null, 400, 'bad request')); | ||
}; | ||
|
||
module.exports = badRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const ConnectDB = require('../util/connectDB'); | ||
const getResponse = require('../util/getResponse'); | ||
const { categoryMap } = require('../util/category'); | ||
const queryTags = require('../util/queryTags'); | ||
const queryTorrents = require('../util/queryTorrents'); | ||
|
||
const list = async (req, res) => { | ||
let { category = '', page = 1, limit = 10 } = Object.assign({}, req.params, req.query); | ||
[page, limit] = [page, limit].map(e => { | ||
if (e <= 0) { | ||
return 1; | ||
} | ||
return parseInt(e, 10); | ||
}); | ||
if (limit > 25) { | ||
return res.json(getResponse(null, 400, 'limit is too large')); | ||
} | ||
|
||
let cat = []; | ||
if (!Number.isNaN(+category)) { | ||
if (category < 0) { | ||
category = -category ^ 2047; | ||
} | ||
Object.entries(categoryMap).forEach(([key, value]) => { | ||
if (+key & +category) { | ||
cat.push(value); | ||
} | ||
}); | ||
} | ||
else { | ||
cat = category.split(/\s*,\s*/).filter(e => e); | ||
} | ||
if (!cat.length) { | ||
return res.json(getResponse(null, 400, 'category is not defined')); | ||
} | ||
|
||
const conn = await new ConnectDB().connect(); | ||
|
||
const result = await conn.query( | ||
`SELECT * FROM gallery WHERE expunged = 0 AND category in (?) | ||
ORDER BY posted DESC LIMIT ? OFFSET ?`, | ||
[cat, limit, (page - 1) * limit] | ||
); | ||
const { total } = (await conn.query( | ||
'SELECT COUNT(*) AS total FROM gallery WHERE expunged = 0 AND category in (?)', | ||
[cat] | ||
))[0]; | ||
|
||
if (!result.length) { | ||
conn.destroy(); | ||
return res.json(getResponse([], 200, 'success', { total })); | ||
} | ||
|
||
const gids = result.map(e => e.gid); | ||
const rootGids = result.map(e => e.root_gid).filter(e => e); | ||
const gidTags = await queryTags(conn, gids); | ||
const gidTorrents = await queryTorrents(conn, rootGids); | ||
|
||
result.forEach(e => { | ||
e.tags = gidTags[e.gid] || []; | ||
e.torrents = gidTorrents[e.root_gid] || []; | ||
}); | ||
|
||
conn.destroy(); | ||
return res.json(getResponse(result, 200, 'success', { total })); | ||
}; | ||
|
||
module.exports = list; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const ConnectDB = require('../util/connectDB'); | ||
const getResponse = require('../util/getResponse'); | ||
const queryTags = require('../util/queryTags'); | ||
const queryTorrents = require('../util/queryTorrents'); | ||
|
||
const gallery = async (req, res) => { | ||
const { gid = '', token = '' } = Object.assign({}, req.params, req.query); | ||
if (!/^\d+$/.test(gid) || !/^[0-9a-f]{10}$/.test(token)) { | ||
return res.json(getResponse(null, 400, 'gid or token is invalid')); | ||
} | ||
|
||
const conn = await new ConnectDB().connect(); | ||
|
||
const result = (await conn.query('SELECT * FROM gallery WHERE gid = ? AND token = ?', [gid, token]))[0]; | ||
if (!result) { | ||
conn.destroy(); | ||
return res.json(getResponse(null, 404, 'no gallery matches gid and token')); | ||
} | ||
|
||
const { root_gid } = result; | ||
const tags = (await queryTags(conn, [gid]))[gid] || []; | ||
let torrents = []; | ||
if (result.root_gid) { | ||
torrents = (await queryTorrents(conn, [root_gid]))[root_gid] || []; | ||
} | ||
|
||
conn.destroy(); | ||
return res.json(getResponse( | ||
{ ...result, tags, torrents }, | ||
200, | ||
'success' | ||
)); | ||
}; | ||
|
||
module.exports = gallery; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const ConnectDB = require('../util/connectDB'); | ||
const getResponse = require('../util/getResponse'); | ||
const queryTags = require('../util/queryTags'); | ||
const queryTorrents = require('../util/queryTorrents'); | ||
|
||
const list = async (req, res) => { | ||
let { page = 1, limit = 10 } = Object.assign({}, req.query); | ||
[page, limit] = [page, limit].map(e => { | ||
if (e <= 0) { | ||
return 1; | ||
} | ||
return parseInt(e, 10); | ||
}); | ||
if (limit > 25) { | ||
return res.json(getResponse(null, 400, 'limit is too large')); | ||
} | ||
|
||
const conn = await new ConnectDB().connect(); | ||
|
||
const result = await conn.query( | ||
'SELECT * FROM gallery WHERE expunged = 0 ORDER BY posted DESC LIMIT ? OFFSET ?', | ||
[limit, (page - 1) * limit] | ||
); | ||
const { total } = (await conn.query('SELECT COUNT(*) AS total FROM gallery WHERE expunged = 0'))[0]; | ||
|
||
if (!result.length) { | ||
conn.destroy(); | ||
return res.json(getResponse([], 200, 'success', { total })); | ||
} | ||
|
||
const gids = result.map(e => e.gid); | ||
const rootGids = result.map(e => e.root_gid).filter(e => e); | ||
const gidTags = await queryTags(conn, gids); | ||
const gidTorrents = await queryTorrents(conn, rootGids); | ||
|
||
result.forEach(e => { | ||
e.tags = gidTags[e.gid] || []; | ||
e.torrents = gidTorrents[e.root_gid] || []; | ||
}); | ||
|
||
conn.destroy(); | ||
return res.json(getResponse(result, 200, 'success', { total })); | ||
}; | ||
|
||
module.exports = list; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const getResponse = require('../util/getResponse'); | ||
|
||
const notFound = (req, res) => { | ||
return res.status(404).json(getResponse(null, 404, 'not found')); | ||
}; | ||
|
||
module.exports = notFound; |
Oops, something went wrong.