Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion middleware/authenticateToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const isWhitelisted = (url, method) => {
const authenticateToken = async (ctx, next) => {
// token 不存在并且在白名单类,免除校验
const token = ctx.headers["authorization"]?.replace("Bearer ", "");

if (isWhitelisted(ctx.path, ctx.method) && !token) {
await next();
return;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"bcrypt": "^5.1.1",
"dotenv": "^16.4.5",
"file-type": "^19.0.0",
"filesize": "^10.1.2",
"joi": "^17.13.3",
"jsonwebtoken": "^9.0.2",
"jszip": "^3.10.1",
Expand Down
12 changes: 8 additions & 4 deletions routers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ const sharp = require("sharp");
const tinify = require("tinify");
const { Op } = require("sequelize");
const { v4: uuidv4 } = require("uuid");
const JSZip = require("jszip");
const { filesize } = require("filesize");

const { detectFileType } = require("../utils/detectFileType");
const Files = require("../models/files");
const JSZip = require("jszip");
const {
imageMimeTypes,
tinifySupportedMimeTypes,
Expand Down Expand Up @@ -224,7 +226,10 @@ router.get("/files", validateQuery(FILES_LIST_GET_QUERY), async (ctx) => {
});

ctx.body = {
items: rows,
items: rows.map((file) => ({
...file.dataValues,
file_size: filesize(file.file_size),
})),
total: count,
};
} catch (error) {
Expand Down Expand Up @@ -432,7 +437,6 @@ router.delete("/files", validateBody(FILES_BODY_BATCH_IDS), async (ctx) => {
router.get("/files/:id/preview", validateParams(FILES_REST_ID), async (ctx) => {
const { id } = ctx.params;
const { type } = ctx.query; // 获取查询参数 'type',可以是 'thumb' 或 'original'

try {
const file = await Files.findOne({
where: {
Expand All @@ -441,7 +445,7 @@ router.get("/files/:id/preview", validateParams(FILES_REST_ID), async (ctx) => {
[Op.or]: [
{ public_expiration: null, is_public: true },
{ public_expiration: { [Op.gt]: new Date() }, is_public: true },
{ created_by: ctx.state.user.id },
{ created_by: ctx.state?.user?.id || null },
],
},
attributes: [
Expand Down
4 changes: 2 additions & 2 deletions routers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ router.get("/users/info", async (ctx) => {
router.post("/logout", async (ctx) => {
const { id } = ctx.state.user;
if (!ctx.state.token) {
ctx.status = 400;
ctx.body = { message: "Token is required" };
ctx.status = 200;
ctx.body = { message: "Invalid Token" };
return;
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ file-type@^19.0.0:
strtok3 "^7.0.0"
token-types "^5.0.1"

filesize@^10.1.2:
version "10.1.2"
resolved "https://registry.yarnpkg.com/filesize/-/filesize-10.1.2.tgz#33bb71c5c134102499f1bc36e6f2863137f6cb0c"
integrity sha512-Dx770ai81ohflojxhU+oG+Z2QGvKdYxgEr9OSA8UVrqhwNHjfH9A8f5NKfg83fEH8ZFA5N5llJo5T3PIoZ4CRA==

fill-range@^7.1.1:
version "7.1.1"
resolved "https://registry.npmmirror.com/fill-range/-/fill-range-7.1.1.tgz"
Expand Down