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