forked from mirror/misskey
Emoji copy
This commit is contained in:
parent
5ceffb2c17
commit
c44e8e6bf1
@ -328,6 +328,7 @@ misskeySource: "ソースコードはここで公開されています:"
|
|||||||
administrator: "管理者"
|
administrator: "管理者"
|
||||||
token: "トークン"
|
token: "トークン"
|
||||||
twoStepAuthentication: "二段階認証"
|
twoStepAuthentication: "二段階認証"
|
||||||
|
moderator: "モデレーター"
|
||||||
|
|
||||||
_2fa:
|
_2fa:
|
||||||
registerDevice: "デバイスを登録"
|
registerDevice: "デバイスを登録"
|
||||||
|
64
src/server/api/endpoints/admin/emoji/copy.ts
Normal file
64
src/server/api/endpoints/admin/emoji/copy.ts
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import $ from 'cafy';
|
||||||
|
import define from '../../../define';
|
||||||
|
import { Emojis } from '../../../../../models';
|
||||||
|
import { genId } from '../../../../../misc/gen-id';
|
||||||
|
import { getConnection } from 'typeorm';
|
||||||
|
import { ApiError } from '../../../error';
|
||||||
|
import { DriveFile } from '../../../../../models/entities/drive-file';
|
||||||
|
import { ID } from '../../../../../misc/cafy-id';
|
||||||
|
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
tags: ['admin'],
|
||||||
|
|
||||||
|
requireCredential: true,
|
||||||
|
requireModerator: true,
|
||||||
|
|
||||||
|
params: {
|
||||||
|
emojiId: {
|
||||||
|
validator: $.type(ID)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
errors: {
|
||||||
|
noSuchEmoji: {
|
||||||
|
message: 'No such emoji.',
|
||||||
|
code: 'NO_SUCH_EMOJI',
|
||||||
|
id: 'e2785b66-dca3-4087-9cac-b93c541cc425'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default define(meta, async (ps, me) => {
|
||||||
|
const emoji = await Emojis.findOne(ps.emojiId);
|
||||||
|
|
||||||
|
if (emoji == null) {
|
||||||
|
throw new ApiError(meta.errors.noSuchEmoji);
|
||||||
|
}
|
||||||
|
|
||||||
|
let driveFile: DriveFile;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Create file
|
||||||
|
driveFile = await uploadFromUrl(emoji.url, null, null, null, false, true);
|
||||||
|
} catch (e) {
|
||||||
|
throw new ApiError();
|
||||||
|
}
|
||||||
|
|
||||||
|
const copied = await Emojis.save({
|
||||||
|
id: genId(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
name: emoji.name,
|
||||||
|
host: null,
|
||||||
|
aliases: [],
|
||||||
|
url: driveFile.url,
|
||||||
|
type: driveFile.type,
|
||||||
|
fileId: driveFile.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: copied.id
|
||||||
|
};
|
||||||
|
});
|
@ -257,7 +257,7 @@ async function deleteOldFile(user: IRemoteUser) {
|
|||||||
* @return Created drive file
|
* @return Created drive file
|
||||||
*/
|
*/
|
||||||
export default async function(
|
export default async function(
|
||||||
user: User,
|
user: User | null,
|
||||||
path: string,
|
path: string,
|
||||||
name: string | null = null,
|
name: string | null = null,
|
||||||
comment: string | null = null,
|
comment: string | null = null,
|
||||||
@ -274,7 +274,7 @@ export default async function(
|
|||||||
// detect name
|
// detect name
|
||||||
const detectedName = name || (info.type.ext ? `untitled.${info.type.ext}` : 'untitled');
|
const detectedName = name || (info.type.ext ? `untitled.${info.type.ext}` : 'untitled');
|
||||||
|
|
||||||
if (!force) {
|
if (user && !force) {
|
||||||
// Check if there is a file with the same hash
|
// Check if there is a file with the same hash
|
||||||
const much = await DriveFiles.findOne({
|
const much = await DriveFiles.findOne({
|
||||||
md5: info.md5,
|
md5: info.md5,
|
||||||
@ -288,7 +288,7 @@ export default async function(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//#region Check drive usage
|
//#region Check drive usage
|
||||||
if (!isLink) {
|
if (user && !isLink) {
|
||||||
const usage = await DriveFiles.clacDriveUsageOf(user);
|
const usage = await DriveFiles.clacDriveUsageOf(user);
|
||||||
|
|
||||||
const instance = await fetchMeta();
|
const instance = await fetchMeta();
|
||||||
@ -315,7 +315,7 @@ export default async function(
|
|||||||
|
|
||||||
const driveFolder = await DriveFolders.findOne({
|
const driveFolder = await DriveFolders.findOne({
|
||||||
id: folderId,
|
id: folderId,
|
||||||
userId: user.id
|
userId: user ? user.id : null
|
||||||
});
|
});
|
||||||
|
|
||||||
if (driveFolder == null) throw new Error('folder-not-found');
|
if (driveFolder == null) throw new Error('folder-not-found');
|
||||||
@ -338,22 +338,24 @@ export default async function(
|
|||||||
properties['avgColor'] = `rgb(${info.avgColor.join(',')}`;
|
properties['avgColor'] = `rgb(${info.avgColor.join(',')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const profile = await UserProfiles.findOne(user.id);
|
const profile = user ? await UserProfiles.findOne(user.id) : null;
|
||||||
|
|
||||||
const folder = await fetchFolder();
|
const folder = await fetchFolder();
|
||||||
|
|
||||||
let file = new DriveFile();
|
let file = new DriveFile();
|
||||||
file.id = genId();
|
file.id = genId();
|
||||||
file.createdAt = new Date();
|
file.createdAt = new Date();
|
||||||
file.userId = user.id;
|
file.userId = user ? user.id : null;
|
||||||
file.userHost = user.host;
|
file.userHost = user ? user.host : null;
|
||||||
file.folderId = folder !== null ? folder.id : null;
|
file.folderId = folder !== null ? folder.id : null;
|
||||||
file.comment = comment;
|
file.comment = comment;
|
||||||
file.properties = properties;
|
file.properties = properties;
|
||||||
file.isLink = isLink;
|
file.isLink = isLink;
|
||||||
file.isSensitive = Users.isLocalUser(user) && profile!.alwaysMarkNsfw ? true :
|
file.isSensitive = user
|
||||||
|
? Users.isLocalUser(user) && profile!.alwaysMarkNsfw ? true :
|
||||||
(sensitive !== null && sensitive !== undefined)
|
(sensitive !== null && sensitive !== undefined)
|
||||||
? sensitive
|
? sensitive
|
||||||
|
: false
|
||||||
: false;
|
: false;
|
||||||
|
|
||||||
if (url !== null) {
|
if (url !== null) {
|
||||||
@ -388,7 +390,7 @@ export default async function(
|
|||||||
|
|
||||||
file = await DriveFiles.findOne({
|
file = await DriveFiles.findOne({
|
||||||
uri: file.uri,
|
uri: file.uri,
|
||||||
userId: user.id
|
userId: user ? user.id : null
|
||||||
}) as DriveFile;
|
}) as DriveFile;
|
||||||
} else {
|
} else {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -401,11 +403,13 @@ export default async function(
|
|||||||
|
|
||||||
logger.succ(`drive file has been created ${file.id}`);
|
logger.succ(`drive file has been created ${file.id}`);
|
||||||
|
|
||||||
|
if (user) {
|
||||||
DriveFiles.pack(file, { self: true }).then(packedFile => {
|
DriveFiles.pack(file, { self: true }).then(packedFile => {
|
||||||
// Publish driveFileCreated event
|
// Publish driveFileCreated event
|
||||||
publishMainStream(user.id, 'driveFileCreated', packedFile);
|
publishMainStream(user.id, 'driveFileCreated', packedFile);
|
||||||
publishDriveStream(user.id, 'fileCreated', packedFile);
|
publishDriveStream(user.id, 'fileCreated', packedFile);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 統計を更新
|
// 統計を更新
|
||||||
driveChart.update(file, true);
|
driveChart.update(file, true);
|
||||||
|
@ -11,7 +11,7 @@ const logger = driveLogger.createSubLogger('downloader');
|
|||||||
|
|
||||||
export default async (
|
export default async (
|
||||||
url: string,
|
url: string,
|
||||||
user: User,
|
user: User | null,
|
||||||
folderId: DriveFolder['id'] | null = null,
|
folderId: DriveFolder['id'] | null = null,
|
||||||
uri: string | null = null,
|
uri: string | null = null,
|
||||||
sensitive = false,
|
sensitive = false,
|
||||||
|
Loading…
Reference in New Issue
Block a user