mirror of
https://github.com/sim1222/misskey.git
synced 2025-07-04 09:50:03 +09:00
Fix avatar/banner proxy (#8346)
* Fix avatar/banner proxy Co-authored-by: mei23 <m@m544.net> * use getAvatarUrl * fix * join avatar and banner to improve performance * join * Update hybrid-timeline.ts * fix Co-authored-by: mei23 <m@m544.net> Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
@ -137,11 +137,6 @@ export class Meta {
|
||||
})
|
||||
public cacheRemoteFiles: boolean;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public proxyRemoteFiles: boolean;
|
||||
|
||||
@Column({
|
||||
...id(),
|
||||
nullable: true,
|
||||
|
@ -106,26 +106,6 @@ export class User {
|
||||
})
|
||||
public tags: string[];
|
||||
|
||||
@Column('varchar', {
|
||||
length: 512, nullable: true,
|
||||
})
|
||||
public avatarUrl: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 512, nullable: true,
|
||||
})
|
||||
public bannerUrl: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
})
|
||||
public avatarBlurhash: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
})
|
||||
public bannerBlurhash: string | null;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
comment: 'Whether the User is suspended.',
|
||||
|
@ -41,7 +41,7 @@ export class DriveFileRepository extends Repository<DriveFile> {
|
||||
return file.properties;
|
||||
}
|
||||
|
||||
public getPublicUrl(file: DriveFile, thumbnail = false, meta?: Meta): string | null {
|
||||
public getPublicUrl(file: DriveFile, thumbnail = false): string | null {
|
||||
// リモートかつメディアプロキシ
|
||||
if (file.uri != null && file.userHost != null && config.mediaProxy != null) {
|
||||
return appendQuery(config.mediaProxy, query({
|
||||
@ -51,7 +51,7 @@ export class DriveFileRepository extends Repository<DriveFile> {
|
||||
}
|
||||
|
||||
// リモートかつ期限切れはローカルプロキシを試みる
|
||||
if (file.uri != null && file.isLink && meta && meta.proxyRemoteFiles) {
|
||||
if (file.uri != null && file.isLink && config.proxyRemoteFiles) {
|
||||
const key = thumbnail ? file.thumbnailAccessKey : file.webpublicAccessKey;
|
||||
|
||||
if (key && !key.match('/')) { // 古いものはここにオブジェクトストレージキーが入ってるので除外
|
||||
@ -136,8 +136,8 @@ export class DriveFileRepository extends Repository<DriveFile> {
|
||||
isSensitive: file.isSensitive,
|
||||
blurhash: file.blurhash,
|
||||
properties: opts.self ? file.properties : this.getPublicProperties(file),
|
||||
url: opts.self ? file.url : this.getPublicUrl(file, false, meta),
|
||||
thumbnailUrl: this.getPublicUrl(file, true, meta),
|
||||
url: opts.self ? file.url : this.getPublicUrl(file, false),
|
||||
thumbnailUrl: this.getPublicUrl(file, true),
|
||||
comment: file.comment,
|
||||
folderId: file.folderId,
|
||||
folder: opts.detail && file.folderId ? DriveFolders.pack(file.folderId, {
|
||||
|
@ -23,10 +23,10 @@ export class NoteReactionRepository extends Repository<NoteReaction> {
|
||||
return {
|
||||
id: reaction.id,
|
||||
createdAt: reaction.createdAt.toISOString(),
|
||||
user: await Users.pack(reaction.userId, me),
|
||||
user: await Users.pack(reaction.user ?? reaction.userId, me),
|
||||
type: convertLegacyReaction(reaction.reaction),
|
||||
...(opts.withNote ? {
|
||||
note: await Notes.pack(reaction.noteId, me),
|
||||
note: await Notes.pack(reaction.note ?? reaction.noteId, me),
|
||||
} : {}),
|
||||
};
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { EntityRepository, Repository, In, Not } from 'typeorm';
|
||||
import Ajv from 'ajv';
|
||||
import { User, ILocalUser, IRemoteUser } from '@/models/entities/user.js';
|
||||
import { Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages, Announcements, AnnouncementReads, Antennas, AntennaNotes, ChannelFollowings, Instances } from '../index.js';
|
||||
import { Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages, Announcements, AnnouncementReads, Antennas, AntennaNotes, ChannelFollowings, Instances, DriveFiles } from '../index.js';
|
||||
import config from '@/config/index.js';
|
||||
import { Packed } from '@/misc/schema.js';
|
||||
import { awaitAll, Promiseable } from '@/prelude/await-all.js';
|
||||
@ -182,13 +182,18 @@ export class UserRepository extends Repository<User> {
|
||||
}
|
||||
|
||||
public getAvatarUrl(user: User): string {
|
||||
if (user.avatarUrl) {
|
||||
return user.avatarUrl;
|
||||
// TODO: avatarIdがあるがavatarがない(JOINされてない)場合のハンドリング
|
||||
if (user.avatar) {
|
||||
return DriveFiles.getPublicUrl(user.avatar, true) || this.getIdenticonUrl(user.id);
|
||||
} else {
|
||||
return `${config.url}/identicon/${user.id}`;
|
||||
return this.getIdenticonUrl(user.id);
|
||||
}
|
||||
}
|
||||
|
||||
public getIdenticonUrl(userId: User['id']): string {
|
||||
return `${config.url}/identicon/${userId}`;
|
||||
}
|
||||
|
||||
public async pack<ExpectsMe extends boolean | null = null, D extends boolean = false>(
|
||||
src: User['id'] | User,
|
||||
me?: { id: User['id'] } | null | undefined,
|
||||
@ -202,7 +207,18 @@ export class UserRepository extends Repository<User> {
|
||||
includeSecrets: false,
|
||||
}, options);
|
||||
|
||||
const user = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
||||
let user: User;
|
||||
|
||||
if (typeof src === 'object') {
|
||||
user = src;
|
||||
if (src.avatar === undefined && src.avatarId) src.avatar = await DriveFiles.findOne(src.avatarId) ?? null;
|
||||
if (src.banner === undefined && src.bannerId) src.banner = await DriveFiles.findOne(src.bannerId) ?? null;
|
||||
} else {
|
||||
user = await this.findOneOrFail(src, {
|
||||
relations: ['avatar', 'banner'],
|
||||
});
|
||||
}
|
||||
|
||||
const meId = me ? me.id : null;
|
||||
const isMe = meId === user.id;
|
||||
|
||||
@ -232,7 +248,7 @@ export class UserRepository extends Repository<User> {
|
||||
username: user.username,
|
||||
host: user.host,
|
||||
avatarUrl: this.getAvatarUrl(user),
|
||||
avatarBlurhash: user.avatarBlurhash,
|
||||
avatarBlurhash: user.avatar?.blurhash || null,
|
||||
avatarColor: null, // 後方互換性のため
|
||||
isAdmin: user.isAdmin || falsy,
|
||||
isModerator: user.isModerator || falsy,
|
||||
@ -256,8 +272,8 @@ export class UserRepository extends Repository<User> {
|
||||
createdAt: user.createdAt.toISOString(),
|
||||
updatedAt: user.updatedAt ? user.updatedAt.toISOString() : null,
|
||||
lastFetchedAt: user.lastFetchedAt ? user.lastFetchedAt.toISOString() : null,
|
||||
bannerUrl: user.bannerUrl,
|
||||
bannerBlurhash: user.bannerBlurhash,
|
||||
bannerUrl: user.banner ? DriveFiles.getPublicUrl(user.banner, false) : null,
|
||||
bannerBlurhash: user.banner?.blurhash || null,
|
||||
bannerColor: null, // 後方互換性のため
|
||||
isLocked: user.isLocked,
|
||||
isSilenced: user.isSilenced || falsy,
|
||||
|
Reference in New Issue
Block a user