Merge branch 'notification-read-api' into swn
This commit is contained in:
@@ -86,7 +86,7 @@ export async function exportBlocking(job: Bull.Job<DbUserJobData>, done: any): P
|
||||
logger.succ(`Exported to: ${path}`);
|
||||
|
||||
const fileName = 'blocking-' + dateFormat(new Date(), 'yyyy-mm-dd-HH-MM-ss') + '.csv';
|
||||
const driveFile = await addFile(user, path, fileName, null, null, true);
|
||||
const driveFile = await addFile({ user, path, name: fileName, force: true });
|
||||
|
||||
logger.succ(`Exported to: ${driveFile.id}`);
|
||||
cleanup();
|
||||
|
@@ -111,7 +111,7 @@ export async function exportCustomEmojis(job: Bull.Job, done: () => void): Promi
|
||||
logger.succ(`Exported to: ${archivePath}`);
|
||||
|
||||
const fileName = 'custom-emojis-' + dateFormat(new Date(), 'yyyy-mm-dd-HH-MM-ss') + '.zip';
|
||||
const driveFile = await addFile(user, archivePath, fileName, null, null, true);
|
||||
const driveFile = await addFile({ user, path: archivePath, name: fileName, force: true });
|
||||
|
||||
logger.succ(`Exported to: ${driveFile.id}`);
|
||||
cleanup();
|
||||
|
@@ -87,7 +87,7 @@ export async function exportFollowing(job: Bull.Job<DbUserJobData>, done: () =>
|
||||
logger.succ(`Exported to: ${path}`);
|
||||
|
||||
const fileName = 'following-' + dateFormat(new Date(), 'yyyy-mm-dd-HH-MM-ss') + '.csv';
|
||||
const driveFile = await addFile(user, path, fileName, null, null, true);
|
||||
const driveFile = await addFile({ user, path, name: fileName, force: true });
|
||||
|
||||
logger.succ(`Exported to: ${driveFile.id}`);
|
||||
cleanup();
|
||||
|
@@ -86,7 +86,7 @@ export async function exportMute(job: Bull.Job<DbUserJobData>, done: any): Promi
|
||||
logger.succ(`Exported to: ${path}`);
|
||||
|
||||
const fileName = 'mute-' + dateFormat(new Date(), 'yyyy-mm-dd-HH-MM-ss') + '.csv';
|
||||
const driveFile = await addFile(user, path, fileName, null, null, true);
|
||||
const driveFile = await addFile({ user, path, name: fileName, force: true });
|
||||
|
||||
logger.succ(`Exported to: ${driveFile.id}`);
|
||||
cleanup();
|
||||
|
@@ -95,7 +95,7 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
|
||||
logger.succ(`Exported to: ${path}`);
|
||||
|
||||
const fileName = 'notes-' + dateFormat(new Date(), 'yyyy-mm-dd-HH-MM-ss') + '.json';
|
||||
const driveFile = await addFile(user, path, fileName, null, null, true);
|
||||
const driveFile = await addFile({ user, path, name: fileName, force: true });
|
||||
|
||||
logger.succ(`Exported to: ${driveFile.id}`);
|
||||
cleanup();
|
||||
|
@@ -63,7 +63,7 @@ export async function exportUserLists(job: Bull.Job<DbUserJobData>, done: any):
|
||||
logger.succ(`Exported to: ${path}`);
|
||||
|
||||
const fileName = 'user-lists-' + dateFormat(new Date(), 'yyyy-mm-dd-HH-MM-ss') + '.csv';
|
||||
const driveFile = await addFile(user, path, fileName, null, null, true);
|
||||
const driveFile = await addFile({ user, path, name: fileName, force: true });
|
||||
|
||||
logger.succ(`Exported to: ${driveFile.id}`);
|
||||
cleanup();
|
||||
|
@@ -59,7 +59,7 @@ export async function importCustomEmojis(job: Bull.Job<DbUserImportJobData>, don
|
||||
await Emojis.delete({
|
||||
name: emojiInfo.name,
|
||||
});
|
||||
const driveFile = await addFile(null, emojiPath, record.fileName, null, null, true);
|
||||
const driveFile = await addFile({ user: null, path: emojiPath, name: record.fileName, force: true });
|
||||
const emoji = await Emojis.insert({
|
||||
id: genId(),
|
||||
updatedAt: new Date(),
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import uploadFromUrl from '@/services/drive/upload-from-url';
|
||||
import { uploadFromUrl } from '@/services/drive/upload-from-url';
|
||||
import { IRemoteUser } from '@/models/entities/user';
|
||||
import Resolver from '../resolver';
|
||||
import { fetchMeta } from '@/misc/fetch-meta';
|
||||
@@ -28,9 +28,15 @@ export async function createImage(actor: IRemoteUser, value: any): Promise<Drive
|
||||
logger.info(`Creating the Image: ${image.url}`);
|
||||
|
||||
const instance = await fetchMeta();
|
||||
const cache = instance.cacheRemoteFiles;
|
||||
|
||||
let file = await uploadFromUrl(image.url, actor, null, image.url, image.sensitive, false, !cache, truncate(image.name, DB_MAX_IMAGE_COMMENT_LENGTH));
|
||||
let file = await uploadFromUrl({
|
||||
url: image.url,
|
||||
user: actor,
|
||||
uri: image.url,
|
||||
sensitive: image.sensitive,
|
||||
isLink: !instance.cacheRemoteFiles,
|
||||
comment: truncate(image.name, DB_MAX_IMAGE_COMMENT_LENGTH)
|
||||
});
|
||||
|
||||
if (file.isLink) {
|
||||
// URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、
|
||||
|
@@ -32,7 +32,7 @@ export const renderActivity = (x: any): IActivity | null => {
|
||||
PropertyValue: 'schema:PropertyValue',
|
||||
value: 'schema:value',
|
||||
// Misskey
|
||||
misskey: `${config.url}/ns#`,
|
||||
misskey: 'https://misskey-hub.net/ns#',
|
||||
'_misskey_content': 'misskey:_misskey_content',
|
||||
'_misskey_quote': 'misskey:_misskey_quote',
|
||||
'_misskey_reaction': 'misskey:_misskey_reaction',
|
||||
|
@@ -37,7 +37,7 @@ export async function resolveUser(username: string, host: string | null, option?
|
||||
});
|
||||
}
|
||||
|
||||
const user = await Users.findOne({ usernameLower, host }, option) as IRemoteUser;
|
||||
const user = await Users.findOne({ usernameLower, host }, option) as IRemoteUser | null;
|
||||
|
||||
const acctLower = `${usernameLower}@${host}`;
|
||||
|
||||
|
@@ -67,7 +67,7 @@ router.get('/notes/:note', async (ctx, next) => {
|
||||
|
||||
const note = await Notes.findOne({
|
||||
id: ctx.params.note,
|
||||
visibility: In(['public', 'home']),
|
||||
visibility: In(['public' as const, 'home' as const]),
|
||||
localOnly: false,
|
||||
});
|
||||
|
||||
@@ -96,7 +96,7 @@ router.get('/notes/:note/activity', async ctx => {
|
||||
const note = await Notes.findOne({
|
||||
id: ctx.params.note,
|
||||
userHost: null,
|
||||
visibility: In(['public', 'home']),
|
||||
visibility: In(['public' as const, 'home' as const]),
|
||||
localOnly: false,
|
||||
});
|
||||
|
||||
|
@@ -10,7 +10,7 @@ export class AuthenticationError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export default async (token: string): Promise<[User | null | undefined, App | null | undefined]> => {
|
||||
export default async (token: string | null): Promise<[User | null | undefined, AccessToken | null | undefined]> => {
|
||||
if (token == null) {
|
||||
return [null, null];
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ 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';
|
||||
import { uploadFromUrl } from '@/services/drive/upload-from-url';
|
||||
import { publishBroadcastStream } from '@/services/stream';
|
||||
|
||||
export const meta = {
|
||||
@@ -54,7 +54,7 @@ export default define(meta, async (ps, me) => {
|
||||
|
||||
try {
|
||||
// Create file
|
||||
driveFile = await uploadFromUrl(emoji.originalUrl, null, null, null, false, true);
|
||||
driveFile = await uploadFromUrl({ url: emoji.originalUrl, user: null, force: true });
|
||||
} catch (e) {
|
||||
throw new ApiError();
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ export default define(meta, async (ps, user) => {
|
||||
const permission = unique(ps.permission.map(v => v.replace(/^(.+)(\/|-)(read|write)$/, '$3:$1')));
|
||||
|
||||
// Create account
|
||||
const app = await Apps.save({
|
||||
const app = await Apps.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
userId: user ? user.id : null,
|
||||
@@ -55,7 +55,7 @@ export default define(meta, async (ps, user) => {
|
||||
permission,
|
||||
callbackUrl: ps.callbackUrl,
|
||||
secret: secret,
|
||||
});
|
||||
}).then(x => Apps.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
return await Apps.pack(app, null, {
|
||||
detail: true,
|
||||
|
@@ -56,14 +56,14 @@ export default define(meta, async (ps, user) => {
|
||||
}
|
||||
}
|
||||
|
||||
const channel = await Channels.save({
|
||||
const channel = await Channels.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
userId: user.id,
|
||||
name: ps.name,
|
||||
description: ps.description || null,
|
||||
bannerId: banner ? banner.id : null,
|
||||
} as Channel);
|
||||
} as Channel).then(x => Channels.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
return await Channels.pack(channel, user);
|
||||
});
|
||||
|
@@ -6,6 +6,7 @@ import define from '../../../define';
|
||||
import { apiLogger } from '../../../logger';
|
||||
import { ApiError } from '../../../error';
|
||||
import { DriveFiles } from '@/models/index';
|
||||
import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits';
|
||||
|
||||
export const meta = {
|
||||
tags: ['drive'],
|
||||
@@ -32,6 +33,11 @@ export const meta = {
|
||||
default: null,
|
||||
},
|
||||
|
||||
comment: {
|
||||
validator: $.optional.nullable.str.max(DB_MAX_IMAGE_COMMENT_LENGTH),
|
||||
default: null,
|
||||
},
|
||||
|
||||
isSensitive: {
|
||||
validator: $.optional.either($.bool, $.str),
|
||||
default: false,
|
||||
@@ -79,7 +85,7 @@ export default define(meta, async (ps, user, _, file, cleanup) => {
|
||||
|
||||
try {
|
||||
// Create file
|
||||
const driveFile = await addFile(user, file.path, name, null, ps.folderId, ps.force, false, null, null, ps.isSensitive);
|
||||
const driveFile = await addFile({ user, path: file.path, name, comment: ps.comment, folderId: ps.folderId, force: ps.force, sensitive: ps.isSensitive });
|
||||
return await DriveFiles.pack(driveFile, { self: true });
|
||||
} catch (e) {
|
||||
apiLogger.error(e);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import { ID } from '@/misc/cafy-id';
|
||||
import ms from 'ms';
|
||||
import uploadFromUrl from '@/services/drive/upload-from-url';
|
||||
import { uploadFromUrl } from '@/services/drive/upload-from-url';
|
||||
import define from '../../../define';
|
||||
import { DriveFiles } from '@/models/index';
|
||||
import { publishMainStream } from '@/services/stream';
|
||||
@@ -54,7 +54,7 @@ export const meta = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, async (ps, user) => {
|
||||
uploadFromUrl(ps.url, user, ps.folderId, null, ps.isSensitive, ps.force, false, ps.comment).then(file => {
|
||||
uploadFromUrl({ url: ps.url, user, folderId: ps.folderId, sensitive: ps.isSensitive, force: ps.force, comment: ps.comment }).then(file => {
|
||||
DriveFiles.pack(file, { self: true }).then(packedFile => {
|
||||
publishMainStream(user.id, 'urlUploadFinished', {
|
||||
marker: ps.marker,
|
||||
|
@@ -130,7 +130,7 @@ export default define(meta, async (ps, user) => {
|
||||
|
||||
const credentialIdString = credentialId.toString('hex');
|
||||
|
||||
await UserSecurityKeys.save({
|
||||
await UserSecurityKeys.insert({
|
||||
userId: user.id,
|
||||
id: credentialIdString,
|
||||
lastUsed: new Date(),
|
||||
|
@@ -45,7 +45,7 @@ export default define(meta, async (ps, user) => {
|
||||
|
||||
const challengeId = genId();
|
||||
|
||||
await AttestationChallenges.save({
|
||||
await AttestationChallenges.insert({
|
||||
userId: user.id,
|
||||
id: challengeId,
|
||||
challenge: hash(Buffer.from(challenge, 'utf-8')).toString('hex'),
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import * as Router from '@koa/router';
|
||||
import config from '@/config/index';
|
||||
import { fetchMeta } from '@/misc/fetch-meta';
|
||||
import { Users } from '@/models/index';
|
||||
// import User from '../models/user';
|
||||
// import Note from '../models/note';
|
||||
import { Users, Notes } from '@/models/index';
|
||||
import { Not, IsNull, MoreThan } from 'typeorm';
|
||||
|
||||
const router = new Router();
|
||||
|
||||
@@ -19,20 +18,21 @@ export const links = [/* (awaiting release) {
|
||||
}];
|
||||
|
||||
const nodeinfo2 = async () => {
|
||||
const now = Date.now();
|
||||
const [
|
||||
meta,
|
||||
// total,
|
||||
// activeHalfyear,
|
||||
// activeMonth,
|
||||
// localPosts,
|
||||
// localComments
|
||||
total,
|
||||
activeHalfyear,
|
||||
activeMonth,
|
||||
localPosts,
|
||||
localComments,
|
||||
] = await Promise.all([
|
||||
fetchMeta(true),
|
||||
// User.count({ host: null }),
|
||||
// User.count({ host: null, updatedAt: { $gt: new Date(Date.now() - 15552000000) } }),
|
||||
// User.count({ host: null, updatedAt: { $gt: new Date(Date.now() - 2592000000) } }),
|
||||
// Note.count({ '_user.host': null, replyId: null }),
|
||||
// Note.count({ '_user.host': null, replyId: { $ne: null } })
|
||||
Users.count({ where: { host: null } }),
|
||||
Users.count({ where: { host: null, updatedAt: MoreThan(new Date(now - 15552000000)) } }),
|
||||
Users.count({ where: { host: null, updatedAt: MoreThan(new Date(now - 2592000000)) } }),
|
||||
Notes.count({ where: { userHost: null, replyId: null } }),
|
||||
Notes.count({ where: { userHost: null, replyId: Not(IsNull()) } }),
|
||||
]);
|
||||
|
||||
const proxyAccount = meta.proxyAccountId ? await Users.pack(meta.proxyAccountId).catch(() => null) : null;
|
||||
@@ -50,9 +50,9 @@ const nodeinfo2 = async () => {
|
||||
},
|
||||
openRegistrations: !meta.disableRegistration,
|
||||
usage: {
|
||||
users: {}, // { total, activeHalfyear, activeMonth },
|
||||
// localPosts,
|
||||
// localComments
|
||||
users: { total, activeHalfyear, activeMonth },
|
||||
localPosts,
|
||||
localComments,
|
||||
},
|
||||
metadata: {
|
||||
nodeName: meta.name,
|
||||
|
@@ -297,33 +297,45 @@ async function deleteOldFile(user: IRemoteUser) {
|
||||
}
|
||||
}
|
||||
|
||||
type AddFileArgs = {
|
||||
/** User who wish to add file */
|
||||
user: { id: User['id']; host: User['host'] } | null;
|
||||
/** File path */
|
||||
path: string;
|
||||
/** Name */
|
||||
name?: string | null;
|
||||
/** Comment */
|
||||
comment?: string | null;
|
||||
/** Folder ID */
|
||||
folderId?: any;
|
||||
/** If set to true, forcibly upload the file even if there is a file with the same hash. */
|
||||
force?: boolean;
|
||||
/** Do not save file to local */
|
||||
isLink?: boolean;
|
||||
/** URL of source (URLからアップロードされた場合(ローカル/リモート)の元URL) */
|
||||
url?: string | null;
|
||||
/** URL of source (リモートインスタンスのURLからアップロードされた場合の元URL) */
|
||||
uri?: string | null;
|
||||
/** Mark file as sensitive */
|
||||
sensitive?: boolean | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add file to drive
|
||||
*
|
||||
* @param user User who wish to add file
|
||||
* @param path File path
|
||||
* @param name Name
|
||||
* @param comment Comment
|
||||
* @param folderId Folder ID
|
||||
* @param force If set to true, forcibly upload the file even if there is a file with the same hash.
|
||||
* @param isLink Do not save file to local
|
||||
* @param url URL of source (URLからアップロードされた場合(ローカル/リモート)の元URL)
|
||||
* @param uri URL of source (リモートインスタンスのURLからアップロードされた場合の元URL)
|
||||
* @param sensitive Mark file as sensitive
|
||||
* @return Created drive file
|
||||
*/
|
||||
export async function addFile(
|
||||
user: { id: User['id']; host: User['host'] } | null,
|
||||
path: string,
|
||||
name: string | null = null,
|
||||
comment: string | null = null,
|
||||
folderId: any = null,
|
||||
force: boolean = false,
|
||||
isLink: boolean = false,
|
||||
url: string | null = null,
|
||||
uri: string | null = null,
|
||||
sensitive: boolean | null = null
|
||||
): Promise<DriveFile> {
|
||||
export async function addFile({
|
||||
user,
|
||||
path,
|
||||
name = null,
|
||||
comment = null,
|
||||
folderId = null,
|
||||
force = false,
|
||||
isLink = false,
|
||||
url = null,
|
||||
uri = null,
|
||||
sensitive = null
|
||||
}: AddFileArgs): Promise<DriveFile> {
|
||||
const info = await getFileInfo(path);
|
||||
logger.info(`${JSON.stringify(info)}`);
|
||||
|
||||
|
@@ -10,16 +10,27 @@ import { DriveFiles } from '@/models/index';
|
||||
|
||||
const logger = driveLogger.createSubLogger('downloader');
|
||||
|
||||
export default async (
|
||||
url: string,
|
||||
user: { id: User['id']; host: User['host'] } | null,
|
||||
folderId: DriveFolder['id'] | null = null,
|
||||
uri: string | null = null,
|
||||
type Args = {
|
||||
url: string;
|
||||
user: { id: User['id']; host: User['host'] } | null;
|
||||
folderId?: DriveFolder['id'] | null;
|
||||
uri?: string | null;
|
||||
sensitive?: boolean;
|
||||
force?: boolean;
|
||||
isLink?: boolean;
|
||||
comment?: string | null;
|
||||
};
|
||||
|
||||
export async function uploadFromUrl({
|
||||
url,
|
||||
user,
|
||||
folderId = null,
|
||||
uri = null,
|
||||
sensitive = false,
|
||||
force = false,
|
||||
link = false,
|
||||
isLink = false,
|
||||
comment = null
|
||||
): Promise<DriveFile> => {
|
||||
}: Args): Promise<DriveFile> {
|
||||
let name = new URL(url).pathname.split('/').pop() || null;
|
||||
if (name == null || !DriveFiles.validateFileName(name)) {
|
||||
name = null;
|
||||
@@ -41,7 +52,7 @@ export default async (
|
||||
let error;
|
||||
|
||||
try {
|
||||
driveFile = await addFile(user, path, name, comment, folderId, force, link, url, uri, sensitive);
|
||||
driveFile = await addFile({ user, path, name, comment, folderId, force, isLink, url, uri, sensitive });
|
||||
logger.succ(`Got: ${driveFile.id}`);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
@@ -59,4 +70,4 @@ export default async (
|
||||
} else {
|
||||
return driveFile!;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ export default async function(follower: { id: User['id']; host: User['host']; ur
|
||||
if (blocking != null) throw new Error('blocking');
|
||||
if (blocked != null) throw new Error('blocked');
|
||||
|
||||
const followRequest = await FollowRequests.save({
|
||||
const followRequest = await FollowRequests.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
followerId: follower.id,
|
||||
@@ -39,7 +39,7 @@ export default async function(follower: { id: User['id']; host: User['host']; ur
|
||||
followeeHost: followee.host,
|
||||
followeeInbox: Users.isRemoteUser(followee) ? followee.inbox : undefined,
|
||||
followeeSharedInbox: Users.isRemoteUser(followee) ? followee.sharedInbox : undefined,
|
||||
});
|
||||
}).then(x => FollowRequests.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
// Publish receiveRequest event
|
||||
if (Users.isLocalUser(followee)) {
|
||||
|
@@ -16,12 +16,12 @@ export async function registerOrFetchInstanceDoc(host: string): Promise<Instance
|
||||
const index = await Instances.findOne({ host });
|
||||
|
||||
if (index == null) {
|
||||
const i = await Instances.save({
|
||||
const i = await Instances.insert({
|
||||
id: genId(),
|
||||
host,
|
||||
caughtAt: new Date(),
|
||||
lastCommunicatedAt: new Date(),
|
||||
});
|
||||
}).then(x => Instances.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
federationChart.update(true);
|
||||
|
||||
|
Reference in New Issue
Block a user