Merge branch 'develop' into notification-read-api
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user