refactor: ♻️ create drive file endpoint

Adjusts ratelimit to 250 files every 10 minutes, fixes error text, fixes reused variable name.
This commit is contained in:
ThatOneCalculator 2023-07-20 16:13:10 -07:00
parent 7364ebdca8
commit 03077a157e
No known key found for this signature in database
GPG key ID: 8703CACD01000000

View file

@ -3,7 +3,7 @@ import { DriveFiles } from "@/models/index.js";
import { DB_MAX_IMAGE_COMMENT_LENGTH } from "@/misc/hard-limits.js"; import { DB_MAX_IMAGE_COMMENT_LENGTH } from "@/misc/hard-limits.js";
import { IdentifiableError } from "@/misc/identifiable-error.js"; import { IdentifiableError } from "@/misc/identifiable-error.js";
import { fetchMeta } from "@/misc/fetch-meta.js"; import { fetchMeta } from "@/misc/fetch-meta.js";
import { HOUR } from "@/const.js"; import { MINUTE } from "@/const.js";
import define from "../../../define.js"; import define from "../../../define.js";
import { apiLogger } from "../../../logger.js"; import { apiLogger } from "../../../logger.js";
import { ApiError } from "../../../error.js"; import { ApiError } from "../../../error.js";
@ -14,8 +14,8 @@ export const meta = {
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: HOUR, duration: MINUTE * 10,
max: 120, max: 250,
}, },
requireFile: true, requireFile: true,
@ -40,7 +40,7 @@ export const meta = {
inappropriate: { inappropriate: {
message: message:
"Cannot upload the file because it has been determined that it possibly contains inappropriate content.", "Cannot upload due to the file possibly containing inappropriate content.",
code: "INAPPROPRIATE", code: "INAPPROPRIATE",
id: "bec5bd69-fba3-43c9-b4fb-2894b66ad5d2", id: "bec5bd69-fba3-43c9-b4fb-2894b66ad5d2",
}, },
@ -95,7 +95,7 @@ export default define(
name = null; name = null;
} }
const meta = await fetchMeta(); const instanceMeta = await fetchMeta();
try { try {
// Create file // Create file
@ -107,8 +107,8 @@ export default define(
folderId: ps.folderId, folderId: ps.folderId,
force: ps.force, force: ps.force,
sensitive: ps.isSensitive, sensitive: ps.isSensitive,
requestIp: meta.enableIpLogging ? ip : null, requestIp: instanceMeta.enableIpLogging ? ip : null,
requestHeaders: meta.enableIpLogging ? headers : null, requestHeaders: instanceMeta.enableIpLogging ? headers : null,
}); });
return await DriveFiles.pack(driveFile, { self: true }); return await DriveFiles.pack(driveFile, { self: true });
} catch (e) { } catch (e) {
@ -123,7 +123,9 @@ export default define(
} }
throw new ApiError(); throw new ApiError();
} finally { } finally {
cleanup!(); if (cleanup !== undefined) {
cleanup();
}
} }
}, },
); );