mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-24 12:56:43 -06:00
Emoji copy
This commit is contained in:
parent
5ceffb2c17
commit
c44e8e6bf1
4 changed files with 87 additions and 18 deletions
|
@ -328,6 +328,7 @@ misskeySource: "ソースコードはここで公開されています:"
|
|||
administrator: "管理者"
|
||||
token: "トークン"
|
||||
twoStepAuthentication: "二段階認証"
|
||||
moderator: "モデレーター"
|
||||
|
||||
_2fa:
|
||||
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
|
||||
*/
|
||||
export default async function(
|
||||
user: User,
|
||||
user: User | null,
|
||||
path: string,
|
||||
name: string | null = null,
|
||||
comment: string | null = null,
|
||||
|
@ -274,7 +274,7 @@ export default async function(
|
|||
// detect name
|
||||
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
|
||||
const much = await DriveFiles.findOne({
|
||||
md5: info.md5,
|
||||
|
@ -288,7 +288,7 @@ export default async function(
|
|||
}
|
||||
|
||||
//#region Check drive usage
|
||||
if (!isLink) {
|
||||
if (user && !isLink) {
|
||||
const usage = await DriveFiles.clacDriveUsageOf(user);
|
||||
|
||||
const instance = await fetchMeta();
|
||||
|
@ -315,7 +315,7 @@ export default async function(
|
|||
|
||||
const driveFolder = await DriveFolders.findOne({
|
||||
id: folderId,
|
||||
userId: user.id
|
||||
userId: user ? user.id : null
|
||||
});
|
||||
|
||||
if (driveFolder == null) throw new Error('folder-not-found');
|
||||
|
@ -338,23 +338,25 @@ export default async function(
|
|||
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();
|
||||
|
||||
let file = new DriveFile();
|
||||
file.id = genId();
|
||||
file.createdAt = new Date();
|
||||
file.userId = user.id;
|
||||
file.userHost = user.host;
|
||||
file.userId = user ? user.id : null;
|
||||
file.userHost = user ? user.host : null;
|
||||
file.folderId = folder !== null ? folder.id : null;
|
||||
file.comment = comment;
|
||||
file.properties = properties;
|
||||
file.isLink = isLink;
|
||||
file.isSensitive = Users.isLocalUser(user) && profile!.alwaysMarkNsfw ? true :
|
||||
(sensitive !== null && sensitive !== undefined)
|
||||
? sensitive
|
||||
: false;
|
||||
file.isSensitive = user
|
||||
? Users.isLocalUser(user) && profile!.alwaysMarkNsfw ? true :
|
||||
(sensitive !== null && sensitive !== undefined)
|
||||
? sensitive
|
||||
: false
|
||||
: false;
|
||||
|
||||
if (url !== null) {
|
||||
file.src = url;
|
||||
|
@ -388,7 +390,7 @@ export default async function(
|
|||
|
||||
file = await DriveFiles.findOne({
|
||||
uri: file.uri,
|
||||
userId: user.id
|
||||
userId: user ? user.id : null
|
||||
}) as DriveFile;
|
||||
} else {
|
||||
logger.error(e);
|
||||
|
@ -401,11 +403,13 @@ export default async function(
|
|||
|
||||
logger.succ(`drive file has been created ${file.id}`);
|
||||
|
||||
DriveFiles.pack(file, { self: true }).then(packedFile => {
|
||||
// Publish driveFileCreated event
|
||||
publishMainStream(user.id, 'driveFileCreated', packedFile);
|
||||
publishDriveStream(user.id, 'fileCreated', packedFile);
|
||||
});
|
||||
if (user) {
|
||||
DriveFiles.pack(file, { self: true }).then(packedFile => {
|
||||
// Publish driveFileCreated event
|
||||
publishMainStream(user.id, 'driveFileCreated', packedFile);
|
||||
publishDriveStream(user.id, 'fileCreated', packedFile);
|
||||
});
|
||||
}
|
||||
|
||||
// 統計を更新
|
||||
driveChart.update(file, true);
|
||||
|
|
|
@ -11,7 +11,7 @@ const logger = driveLogger.createSubLogger('downloader');
|
|||
|
||||
export default async (
|
||||
url: string,
|
||||
user: User,
|
||||
user: User | null,
|
||||
folderId: DriveFolder['id'] | null = null,
|
||||
uri: string | null = null,
|
||||
sensitive = false,
|
||||
|
|
Loading…
Reference in a new issue