mirror of
https://github.com/hotomoe/hotomoe
synced 2024-12-12 05:38:12 +09:00
Refactor
This commit is contained in:
parent
f64100226d
commit
1a51b98700
20
src/misc/get-drive-file-url.ts
Normal file
20
src/misc/get-drive-file-url.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { IDriveFile } from '../models/drive-file';
|
||||||
|
import config from '../config';
|
||||||
|
|
||||||
|
export default function(file: IDriveFile, thumbnail = false): string {
|
||||||
|
if (file == null) return null;
|
||||||
|
|
||||||
|
if (file.metadata.withoutChunks) {
|
||||||
|
if (thumbnail) {
|
||||||
|
return file.metadata.thumbnailUrl || file.metadata.url;
|
||||||
|
} else {
|
||||||
|
return file.metadata.url;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (thumbnail) {
|
||||||
|
return `${config.drive_url}/${file._id}?thumbnail`;
|
||||||
|
} else {
|
||||||
|
return `${config.drive_url}/${file._id}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
import * as mongo from 'mongodb';
|
import * as mongo from 'mongodb';
|
||||||
const deepcopy = require('deepcopy');
|
const deepcopy = require('deepcopy');
|
||||||
import { pack as packFolder } from './drive-folder';
|
import { pack as packFolder } from './drive-folder';
|
||||||
import config from '../config';
|
|
||||||
import monkDb, { nativeDbConn } from '../db/mongodb';
|
import monkDb, { nativeDbConn } from '../db/mongodb';
|
||||||
import isObjectId from '../misc/is-objectid';
|
import isObjectId from '../misc/is-objectid';
|
||||||
|
import getDriveFileUrl from '../misc/get-drive-file-url';
|
||||||
|
|
||||||
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
|
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
|
||||||
DriveFile.createIndex('md5');
|
DriveFile.createIndex('md5');
|
||||||
@ -33,7 +33,14 @@ export type IMetadata = {
|
|||||||
thumbnailUrl?: string;
|
thumbnailUrl?: string;
|
||||||
src?: string;
|
src?: string;
|
||||||
deletedAt?: Date;
|
deletedAt?: Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* このファイルの中身データがMongoDB内に保存されているのか否か
|
||||||
|
* オブジェクトストレージを利用している or リモートサーバーへの直リンクである
|
||||||
|
* な場合は false になります
|
||||||
|
*/
|
||||||
withoutChunks?: boolean;
|
withoutChunks?: boolean;
|
||||||
|
|
||||||
storage?: string;
|
storage?: string;
|
||||||
storageProps?: any;
|
storageProps?: any;
|
||||||
isSensitive?: boolean;
|
isSensitive?: boolean;
|
||||||
@ -128,8 +135,8 @@ export const pack = (
|
|||||||
|
|
||||||
_target = Object.assign(_target, _file.metadata);
|
_target = Object.assign(_target, _file.metadata);
|
||||||
|
|
||||||
_target.url = _file.metadata.url ? _file.metadata.url : `${config.drive_url}/${_target.id}/${encodeURIComponent(_target.name)}`;
|
_target.url = getDriveFileUrl(file);
|
||||||
_target.thumbnailUrl = _file.metadata.thumbnailUrl ? _file.metadata.thumbnailUrl : _file.metadata.url ? _file.metadata.url : `${config.drive_url}/${_target.id}/${encodeURIComponent(_target.name)}?thumbnail`;
|
_target.thumbnailUrl = getDriveFileUrl(file, true);
|
||||||
_target.isRemote = _file.metadata.isRemote;
|
_target.isRemote = _file.metadata.isRemote;
|
||||||
|
|
||||||
if (_target.properties == null) _target.properties = {};
|
if (_target.properties == null) _target.properties = {};
|
||||||
|
@ -261,16 +261,6 @@ export const pack = (
|
|||||||
|
|
||||||
if (_user.avatarUrl == null) {
|
if (_user.avatarUrl == null) {
|
||||||
_user.avatarUrl = `${config.drive_url}/default-avatar.jpg`;
|
_user.avatarUrl = `${config.drive_url}/default-avatar.jpg`;
|
||||||
|
|
||||||
// 互換性のため
|
|
||||||
if (_user.avatarId) {
|
|
||||||
_user.avatarUrl = `${config.drive_url}/${_user.avatarId}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 互換性のため
|
|
||||||
if (_user.bannerId && _user.bannerUrl == null) {
|
|
||||||
_user.bannerUrl = `${config.drive_url}/${_user.bannerId}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!meId || !meId.equals(_user.id) || !opts.detail) {
|
if (!meId || !meId.equals(_user.id) || !opts.detail) {
|
||||||
|
@ -15,6 +15,7 @@ import { URL } from 'url';
|
|||||||
import { resolveNote } from './note';
|
import { resolveNote } from './note';
|
||||||
import registerInstance from '../../../services/register-instance';
|
import registerInstance from '../../../services/register-instance';
|
||||||
import Instance from '../../../models/instance';
|
import Instance from '../../../models/instance';
|
||||||
|
import getDriveFileUrl from '../../../misc/get-drive-file-url';
|
||||||
|
|
||||||
const log = debug('misskey:activitypub');
|
const log = debug('misskey:activitypub');
|
||||||
|
|
||||||
@ -303,8 +304,8 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: obje
|
|||||||
featured: person.featured,
|
featured: person.featured,
|
||||||
avatarId: avatar ? avatar._id : null,
|
avatarId: avatar ? avatar._id : null,
|
||||||
bannerId: banner ? banner._id : null,
|
bannerId: banner ? banner._id : null,
|
||||||
avatarUrl: (avatar && avatar.metadata.thumbnailUrl) ? avatar.metadata.thumbnailUrl : (avatar && avatar.metadata.url) ? avatar.metadata.url : null,
|
avatarUrl: getDriveFileUrl(avatar, true),
|
||||||
bannerUrl: banner && banner.metadata.url ? banner.metadata.url : null,
|
bannerUrl: getDriveFileUrl(banner, true),
|
||||||
description: htmlToMFM(person.summary),
|
description: htmlToMFM(person.summary),
|
||||||
followersCount,
|
followersCount,
|
||||||
followingCount,
|
followingCount,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import config from '../../../config';
|
|
||||||
import { IDriveFile } from '../../../models/drive-file';
|
import { IDriveFile } from '../../../models/drive-file';
|
||||||
|
import getDriveFileUrl from '../../../misc/get-drive-file-url';
|
||||||
|
|
||||||
export default (file: IDriveFile) => ({
|
export default (file: IDriveFile) => ({
|
||||||
type: 'Document',
|
type: 'Document',
|
||||||
mediaType: file.contentType,
|
mediaType: file.contentType,
|
||||||
url: file.metadata.url || `${config.drive_url}/${file._id}`
|
url: getDriveFileUrl(file)
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import config from '../../../config';
|
|
||||||
import { IDriveFile } from '../../../models/drive-file';
|
import { IDriveFile } from '../../../models/drive-file';
|
||||||
|
import getDriveFileUrl from '../../../misc/get-drive-file-url';
|
||||||
|
|
||||||
export default (file: IDriveFile) => ({
|
export default (file: IDriveFile) => ({
|
||||||
type: 'Image',
|
type: 'Image',
|
||||||
url: file.metadata.url || `${config.drive_url}/${file._id}`,
|
url: getDriveFileUrl(file),
|
||||||
sensitive: file.metadata.isSensitive
|
sensitive: file.metadata.isSensitive
|
||||||
});
|
});
|
||||||
|
@ -4,9 +4,9 @@ import { publishMainStream } from '../../../../stream';
|
|||||||
import DriveFile from '../../../../models/drive-file';
|
import DriveFile from '../../../../models/drive-file';
|
||||||
import acceptAllFollowRequests from '../../../../services/following/requests/accept-all';
|
import acceptAllFollowRequests from '../../../../services/following/requests/accept-all';
|
||||||
import { IApp } from '../../../../models/app';
|
import { IApp } from '../../../../models/app';
|
||||||
import config from '../../../../config';
|
|
||||||
import { publishToFollowers } from '../../../../services/i/update';
|
import { publishToFollowers } from '../../../../services/i/update';
|
||||||
import getParams from '../../get-params';
|
import getParams from '../../get-params';
|
||||||
|
import getDriveFileUrl from '../../../../misc/get-drive-file-url';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
@ -129,7 +129,7 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a
|
|||||||
if (avatar == null) return rej('avatar not found');
|
if (avatar == null) return rej('avatar not found');
|
||||||
if (!avatar.contentType.startsWith('image/')) return rej('avatar not an image');
|
if (!avatar.contentType.startsWith('image/')) return rej('avatar not an image');
|
||||||
|
|
||||||
updates.avatarUrl = avatar.metadata.thumbnailUrl || avatar.metadata.url || `${config.drive_url}/${avatar._id}`;
|
updates.avatarUrl = getDriveFileUrl(avatar, true);
|
||||||
|
|
||||||
if (avatar.metadata.properties.avgColor) {
|
if (avatar.metadata.properties.avgColor) {
|
||||||
updates.avatarColor = avatar.metadata.properties.avgColor;
|
updates.avatarColor = avatar.metadata.properties.avgColor;
|
||||||
@ -144,7 +144,7 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a
|
|||||||
if (banner == null) return rej('banner not found');
|
if (banner == null) return rej('banner not found');
|
||||||
if (!banner.contentType.startsWith('image/')) return rej('banner not an image');
|
if (!banner.contentType.startsWith('image/')) return rej('banner not an image');
|
||||||
|
|
||||||
updates.bannerUrl = banner.metadata.url || `${config.drive_url}/${banner._id}`;
|
updates.bannerUrl = getDriveFileUrl(banner, true);
|
||||||
|
|
||||||
if (banner.metadata.properties.avgColor) {
|
if (banner.metadata.properties.avgColor) {
|
||||||
updates.bannerColor = banner.metadata.properties.avgColor;
|
updates.bannerColor = banner.metadata.properties.avgColor;
|
||||||
@ -162,7 +162,7 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a
|
|||||||
|
|
||||||
if (wallpaper == null) return rej('wallpaper not found');
|
if (wallpaper == null) return rej('wallpaper not found');
|
||||||
|
|
||||||
updates.wallpaperUrl = wallpaper.metadata.url || `${config.drive_url}/${wallpaper._id}`;
|
updates.wallpaperUrl = getDriveFileUrl(wallpaper);
|
||||||
|
|
||||||
if (wallpaper.metadata.properties.avgColor) {
|
if (wallpaper.metadata.properties.avgColor) {
|
||||||
updates.wallpaperColor = wallpaper.metadata.properties.avgColor;
|
updates.wallpaperColor = wallpaper.metadata.properties.avgColor;
|
||||||
|
Loading…
Reference in New Issue
Block a user