feat(server): add emoji publicUrl
This commit is contained in:
parent
7627c43dee
commit
fe5e6709a5
11 changed files with 40 additions and 15 deletions
15
packages/backend/migration/1642611822809-emoji-url.js
Normal file
15
packages/backend/migration/1642611822809-emoji-url.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
const { MigrationInterface, QueryRunner } = require("typeorm");
|
||||
|
||||
module.exports = class emojiUrl1642611822809 {
|
||||
name = 'emojiUrl1642611822809'
|
||||
|
||||
async up(queryRunner) {
|
||||
await queryRunner.query(`ALTER TABLE "emoji" RENAME COLUMN "url" TO "originalUrl"`);
|
||||
await queryRunner.query(`ALTER TABLE "emoji" ADD "publicUrl" character varying(512) NOT NULL DEFAULT ''`);
|
||||
}
|
||||
|
||||
async down(queryRunner) {
|
||||
await queryRunner.query(`ALTER TABLE "emoji" DROP COLUMN "originalUrl"`);
|
||||
await queryRunner.query(`ALTER TABLE "emoji" RENAME COLUMN "originalUrl" TO "url"`);
|
||||
}
|
||||
}
|
|
@ -62,7 +62,7 @@ export async function populateEmoji(emojiName: string, noteUserHost: string | nu
|
|||
if (emoji == null) return null;
|
||||
|
||||
const isLocal = emoji.host == null;
|
||||
const url = isLocal ? emoji.url : `${config.url}/proxy/image.png?${query({ url: emoji.url })}`;
|
||||
const url = isLocal ? emoji.publicUrl : `${config.url}/proxy/image.png?${query({ url: emoji.publicUrl })}`;
|
||||
|
||||
return {
|
||||
name: emojiName,
|
||||
|
|
|
@ -32,13 +32,19 @@ export class Emoji {
|
|||
@Column('varchar', {
|
||||
length: 512,
|
||||
})
|
||||
public url: string;
|
||||
public originalUrl: string;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 512,
|
||||
})
|
||||
public publicUrl: string;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 512, nullable: true,
|
||||
})
|
||||
public uri: string | null;
|
||||
|
||||
// publicUrlの方のtypeが入る
|
||||
@Column('varchar', {
|
||||
length: 64, nullable: true,
|
||||
})
|
||||
|
|
|
@ -15,7 +15,8 @@ export class EmojiRepository extends Repository<Emoji> {
|
|||
name: emoji.name,
|
||||
category: emoji.category,
|
||||
host: emoji.host,
|
||||
url: emoji.url,
|
||||
// || emoji.originalUrl してるのは後方互換性のため
|
||||
url: emoji.publicUrl || emoji.originalUrl,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ export async function exportCustomEmojis(job: Bull.Job, done: () => void): Promi
|
|||
let downloaded = false;
|
||||
|
||||
try {
|
||||
await downloadUrl(emoji.url, emojiPath);
|
||||
await downloadUrl(emoji.originalUrl, emojiPath);
|
||||
downloaded = true;
|
||||
} catch (e) { // TODO: 何度か再試行
|
||||
logger.error(e);
|
||||
|
|
|
@ -67,8 +67,9 @@ export async function importCustomEmojis(job: Bull.Job<DbUserImportJobData>, don
|
|||
category: emojiInfo.category,
|
||||
host: null,
|
||||
aliases: emojiInfo.aliases,
|
||||
url: driveFile.url,
|
||||
type: driveFile.type,
|
||||
originalUrl: driveFile.url,
|
||||
publicUrl: driveFile.webpublicUrl ?? driveFile.url,
|
||||
type: driveFile.webpublicType ?? driveFile.type,
|
||||
}).then(x => Emojis.findOneOrFail(x.identifiers[0]));
|
||||
}
|
||||
|
||||
|
|
|
@ -347,7 +347,8 @@ export async function extractEmojis(tags: IObject | IObject[], host: string): Pr
|
|||
host,
|
||||
name,
|
||||
uri: tag.id,
|
||||
url: tag.icon!.url,
|
||||
originalUrl: tag.icon!.url,
|
||||
publicUrl: tag.icon!.url,
|
||||
updatedAt: new Date(),
|
||||
aliases: [],
|
||||
} as Partial<Emoji>).then(x => Emojis.findOneOrFail(x.identifiers[0]));
|
||||
|
|
|
@ -9,6 +9,6 @@ export default (emoji: Emoji) => ({
|
|||
icon: {
|
||||
type: 'Image',
|
||||
mediaType: emoji.type || 'image/png',
|
||||
url: emoji.url,
|
||||
url: emoji.publicUrl,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -45,8 +45,9 @@ export default define(meta, async (ps, me) => {
|
|||
category: null,
|
||||
host: null,
|
||||
aliases: [],
|
||||
url: file.url,
|
||||
type: file.type,
|
||||
originalUrl: file.url,
|
||||
publicUrl: file.webpublicUrl ?? file.url,
|
||||
type: file.webpublicType ?? file.type,
|
||||
}).then(x => Emojis.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
|
|
|
@ -54,7 +54,7 @@ export default define(meta, async (ps, me) => {
|
|||
|
||||
try {
|
||||
// Create file
|
||||
driveFile = await uploadFromUrl(emoji.url, null, null, null, false, true);
|
||||
driveFile = await uploadFromUrl(emoji.originalUrl, null, null, null, false, true);
|
||||
} catch (e) {
|
||||
throw new ApiError();
|
||||
}
|
||||
|
@ -65,9 +65,9 @@ export default define(meta, async (ps, me) => {
|
|||
name: emoji.name,
|
||||
host: null,
|
||||
aliases: [],
|
||||
url: driveFile.url,
|
||||
type: driveFile.type,
|
||||
fileId: driveFile.id,
|
||||
originalUrl: driveFile.url,
|
||||
publicUrl: driveFile.webpublicUrl ?? driveFile.url,
|
||||
type: driveFile.webpublicType ?? driveFile.type,
|
||||
}).then(x => Emojis.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
|
|
|
@ -87,7 +87,7 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note,
|
|||
if (emoji) {
|
||||
emoji = {
|
||||
name: emoji.host ? `${emoji.name}@${emoji.host}` : `${emoji.name}@.`,
|
||||
url: emoji.url,
|
||||
url: emoji.publicUrl,
|
||||
} as any;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue