Run format
This commit is contained in:
parent
913de651db
commit
968657d26e
7 changed files with 35 additions and 27 deletions
|
@ -8,8 +8,6 @@ export class AddDriveFileUsage1713451569342 implements MigrationInterface {
|
|||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "drive_file" DROP COLUMN "usageHint"`
|
||||
);
|
||||
await queryRunner.query(`ALTER TABLE "drive_file" DROP COLUMN "usageHint"`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,10 @@ import type { CacheableRemoteUser } from "@/models/entities/user.js";
|
|||
import Resolver from "../resolver.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { apLogger } from "../logger.js";
|
||||
import type { DriveFile, DriveFileUsageHint } from "@/models/entities/drive-file.js";
|
||||
import type {
|
||||
DriveFile,
|
||||
DriveFileUsageHint,
|
||||
} from "@/models/entities/drive-file.js";
|
||||
import { DriveFiles } from "@/models/index.js";
|
||||
import { truncate } from "@/misc/truncate.js";
|
||||
import { DB_MAX_IMAGE_COMMENT_LENGTH } from "@/misc/hard-limits.js";
|
||||
|
@ -16,7 +19,7 @@ const logger = apLogger;
|
|||
export async function createImage(
|
||||
actor: CacheableRemoteUser,
|
||||
value: any,
|
||||
usage: DriveFileUsageHint
|
||||
usage: DriveFileUsageHint,
|
||||
): Promise<DriveFile> {
|
||||
// Skip if author is frozen.
|
||||
if (actor.isSuspended) {
|
||||
|
@ -44,7 +47,7 @@ export async function createImage(
|
|||
sensitive: image.sensitive,
|
||||
isLink: !instance.cacheRemoteFiles,
|
||||
comment: truncate(image.name, DB_MAX_IMAGE_COMMENT_LENGTH),
|
||||
usageHint: usage
|
||||
usageHint: usage,
|
||||
});
|
||||
|
||||
if (file.isLink) {
|
||||
|
|
|
@ -213,7 +213,8 @@ export async function createNote(
|
|||
? (
|
||||
await Promise.all(
|
||||
note.attachment.map(
|
||||
(x) => limit(() => resolveImage(actor, x, null)) as Promise<DriveFile>,
|
||||
(x) =>
|
||||
limit(() => resolveImage(actor, x, null)) as Promise<DriveFile>,
|
||||
),
|
||||
)
|
||||
).filter((image) => image != null)
|
||||
|
|
|
@ -366,7 +366,11 @@ export async function createPerson(
|
|||
[person.icon, person.image].map((img, index) =>
|
||||
img == null
|
||||
? Promise.resolve(null)
|
||||
: resolveImage(user, img, index === 0 ? "user_avatar" : index === 1 ? "user_banner" : null).catch(() => null)
|
||||
: resolveImage(
|
||||
user,
|
||||
img,
|
||||
index === 0 ? "user_avatar" : index === 1 ? "user_banner" : null,
|
||||
).catch(() => null),
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -442,7 +446,11 @@ export async function updatePerson(
|
|||
[person.icon, person.image].map((img, index) =>
|
||||
img == null
|
||||
? Promise.resolve(null)
|
||||
: resolveImage(user, img, index === 0 ? "user_avatar" : index === 1 ? "user_banner" : null).catch(() => null),
|
||||
: resolveImage(
|
||||
user,
|
||||
img,
|
||||
index === 0 ? "user_avatar" : index === 1 ? "user_banner" : null,
|
||||
).catch(() => null),
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -563,13 +571,13 @@ export async function updatePerson(
|
|||
|
||||
if (avatar) {
|
||||
if (user?.avatarId)
|
||||
await DriveFiles.update(user.avatarId, {usageHint: null});
|
||||
await DriveFiles.update(user.avatarId, { usageHint: null });
|
||||
updates.avatarId = avatar.id;
|
||||
}
|
||||
|
||||
if (banner) {
|
||||
if (user?.bannerId)
|
||||
await DriveFiles.update(user.bannerId, {usageHint: null});
|
||||
await DriveFiles.update(user.bannerId, { usageHint: null });
|
||||
updates.bannerId = banner.id;
|
||||
}
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ export default define(meta, paramDef, async (ps, _user, token) => {
|
|||
if (ps.emailNotificationTypes !== undefined)
|
||||
profileUpdates.emailNotificationTypes = ps.emailNotificationTypes;
|
||||
|
||||
let avatar: DriveFile | null = null
|
||||
let avatar: DriveFile | null = null;
|
||||
if (ps.avatarId) {
|
||||
avatar = await DriveFiles.findOneBy({ id: ps.avatarId });
|
||||
|
||||
|
@ -252,7 +252,7 @@ export default define(meta, paramDef, async (ps, _user, token) => {
|
|||
throw new ApiError(meta.errors.avatarNotAnImage);
|
||||
}
|
||||
|
||||
let banner: DriveFile | null = null
|
||||
let banner: DriveFile | null = null;
|
||||
if (ps.bannerId) {
|
||||
banner = await DriveFiles.findOneBy({ id: ps.bannerId });
|
||||
|
||||
|
@ -332,19 +332,17 @@ export default define(meta, paramDef, async (ps, _user, token) => {
|
|||
//#endregion
|
||||
|
||||
// Update old/new avatar usage hints
|
||||
if (avatar)
|
||||
{
|
||||
if (avatar) {
|
||||
if (user.avatarId)
|
||||
await DriveFiles.update(user.avatarId, {usageHint: null});
|
||||
await DriveFiles.update(avatar.id, {usageHint: "user_avatar"});
|
||||
await DriveFiles.update(user.avatarId, { usageHint: null });
|
||||
await DriveFiles.update(avatar.id, { usageHint: "user_avatar" });
|
||||
}
|
||||
|
||||
// Update old/new banner usage hints
|
||||
if (banner)
|
||||
{
|
||||
if (banner) {
|
||||
if (user.bannerId)
|
||||
await DriveFiles.update(user.bannerId, {usageHint: null});
|
||||
await DriveFiles.update(banner.id, {usageHint: "user_banner"});
|
||||
await DriveFiles.update(user.bannerId, { usageHint: null });
|
||||
await DriveFiles.update(banner.id, { usageHint: "user_banner" });
|
||||
}
|
||||
|
||||
if (Object.keys(updates).length > 0) await Users.update(user.id, updates);
|
||||
|
|
|
@ -75,7 +75,7 @@ async function save(
|
|||
type: string,
|
||||
hash: string,
|
||||
size: number,
|
||||
usage: DriveFileUsageHint = null
|
||||
usage: DriveFileUsageHint = null,
|
||||
): Promise<DriveFile> {
|
||||
// thunbnail, webpublic を必要なら生成
|
||||
const alts = await generateAlts(path, type, !file.uri);
|
||||
|
@ -649,7 +649,7 @@ export async function addFile({
|
|||
info.type.mime,
|
||||
info.md5,
|
||||
info.size,
|
||||
usageHint
|
||||
usageHint,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import type { User } from "@/models/entities/user.js";
|
|||
import { createTemp } from "@/misc/create-temp.js";
|
||||
import { downloadUrl, isPrivateIp } from "@/misc/download-url.js";
|
||||
import type { DriveFolder } from "@/models/entities/drive-folder.js";
|
||||
import type { DriveFile } from "@/models/entities/drive-file.js";
|
||||
import type { DriveFile, DriveFileUsageHint } from "@/models/entities/drive-file.js";
|
||||
import { DriveFiles } from "@/models/index.js";
|
||||
import { driveLogger } from "./logger.js";
|
||||
import { addFile } from "./add-file.js";
|
||||
|
@ -26,7 +26,7 @@ type Args = {
|
|||
comment?: string | null;
|
||||
requestIp?: string | null;
|
||||
requestHeaders?: Record<string, string> | null;
|
||||
usageHint?: string | null;
|
||||
usageHint?: DriveFileUsageHint;
|
||||
};
|
||||
|
||||
export async function uploadFromUrl({
|
||||
|
@ -40,7 +40,7 @@ export async function uploadFromUrl({
|
|||
comment = null,
|
||||
requestIp = null,
|
||||
requestHeaders = null,
|
||||
usageHint = null
|
||||
usageHint = null,
|
||||
}: Args): Promise<DriveFile> {
|
||||
const parsedUrl = new URL(url);
|
||||
if (
|
||||
|
@ -81,7 +81,7 @@ export async function uploadFromUrl({
|
|||
sensitive,
|
||||
requestIp,
|
||||
requestHeaders,
|
||||
usageHint
|
||||
usageHint,
|
||||
});
|
||||
logger.succ(`Got: ${driveFile.id}`);
|
||||
return driveFile;
|
||||
|
|
Loading…
Reference in a new issue