アニメーション画像を無効にする際、サーバーサイドではなくクライアントサイドでURLを変更するように

This commit is contained in:
syuilo
2019-02-05 03:51:54 +09:00
parent f014b7ae0e
commit 861302f0fd
14 changed files with 40 additions and 56 deletions

View File

@ -1,11 +1,10 @@
import * as mongo from 'mongodb';
import * as deepcopy from 'deepcopy';
import { pack as packFolder } from './drive-folder';
import { pack as packUser, IUser } from './user';
import { pack as packUser } from './user';
import monkDb, { nativeDbConn, dbLogger } from '../db/mongodb';
import isObjectId from '../misc/is-objectid';
import getDriveFileUrl, { getOriginalUrl } from '../misc/get-drive-file-url';
import wrapUrl from '../misc/wrap-url';
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
DriveFile.createIndex('md5');
@ -134,7 +133,6 @@ export const packMany = (
detail?: boolean
self?: boolean,
withUser?: boolean,
me?: string | mongo.ObjectID | IUser,
}
) => {
return Promise.all(files.map(f => pack(f, options)));
@ -149,7 +147,6 @@ export const pack = (
detail?: boolean,
self?: boolean,
withUser?: boolean,
me?: string | mongo.ObjectID | IUser,
}
) => new Promise<any>(async (resolve, reject) => {
const opts = Object.assign({
@ -192,11 +189,6 @@ export const pack = (
_target.url = getDriveFileUrl(_file);
_target.thumbnailUrl = getDriveFileUrl(_file, true);
if (_target.thumbnailUrl != null) {
_target.thumbnailUrl = wrapUrl(_target.thumbnailUrl, options.me);
}
_target.isRemote = _file.metadata.isRemote;
if (_target.properties == null) _target.properties = {};

View File

@ -11,7 +11,6 @@ import Reaction from './note-reaction';
import { packMany as packFileMany, IDriveFile } from './drive-file';
import Following from './following';
import Emoji from './emoji';
import wrapUrl from '../misc/wrap-url';
const Note = db.get<INote>('notes');
Note.createIndex('uri', { sparse: true, unique: true });
@ -248,14 +247,11 @@ export const pack = async (
fields: { _id: false }
});
} else {
_note.emojis = (await Emoji.find({
_note.emojis = Emoji.find({
name: { $in: _note.emojis },
host: host
}, {
fields: { _id: false }
})).map(emoji => async () => {
emoji.url = await wrapUrl(emoji.url, me);
return emoji;
});
}
}
@ -278,7 +274,7 @@ export const pack = async (
if (_note.geo) delete _note.geo.type;
// Populate user
_note.user = packUser(_note.userId, me);
_note.user = packUser(_note.userId, meId);
// Populate app
if (_note.appId) {
@ -286,7 +282,7 @@ export const pack = async (
}
// Populate files
_note.files = packFileMany(_note.fileIds || [], { me });
_note.files = packFileMany(_note.fileIds || []);
// Some counts
_note.renoteCount = _note.renoteCount || 0;

View File

@ -12,7 +12,6 @@ import config from '../config';
import FollowRequest from './follow-request';
import fetchMeta from '../misc/fetch-meta';
import Emoji from './emoji';
import wrapUrl from '../misc/wrap-url';
const User = db.get<IUser>('users');
@ -345,8 +344,6 @@ export const pack = (
if (_user.avatarUrl == null) {
_user.avatarUrl = `${config.drive_url}/default-avatar.jpg`;
} else {
_user.avatarUrl = wrapUrl(_user.avatarUrl, me);
}
if (!meId || !meId.equals(_user.id) || !opts.detail) {
@ -371,7 +368,7 @@ export const pack = (
if (opts.detail) {
if (_user.pinnedNoteIds) {
// Populate pinned notes
_user.pinnedNotes = packNoteMany(_user.pinnedNoteIds, me, {
_user.pinnedNotes = packNoteMany(_user.pinnedNoteIds, meId, {
detail: true
});
}
@ -400,14 +397,11 @@ export const pack = (
// カスタム絵文字添付
if (_user.emojis) {
_user.emojis = (await Emoji.find({
_user.emojis = Emoji.find({
name: { $in: _user.emojis },
host: _user.host
}, {
fields: { _id: false }
})).map(emoji => {
emoji.url = wrapUrl(emoji.url, me);
return emoji;
});
}