mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-25 08:26:43 -06:00
各種カウントを復活させたりなど
This commit is contained in:
parent
62171dce22
commit
2259747072
2 changed files with 56 additions and 16 deletions
|
@ -6,6 +6,7 @@ import User, { validateUsername, isValidName, isValidDescription } from '../../m
|
||||||
import webFinger from '../webfinger';
|
import webFinger from '../webfinger';
|
||||||
import Resolver from './resolver';
|
import Resolver from './resolver';
|
||||||
import uploadFromUrl from '../../services/drive/upload-from-url';
|
import uploadFromUrl from '../../services/drive/upload-from-url';
|
||||||
|
import { isCollectionOrOrderedCollection } from './type';
|
||||||
|
|
||||||
export default async (value, verifier?: string) => {
|
export default async (value, verifier?: string) => {
|
||||||
const id = value.id || value;
|
const id = value.id || value;
|
||||||
|
@ -30,7 +31,21 @@ export default async (value, verifier?: string) => {
|
||||||
throw new Error('invalid person');
|
throw new Error('invalid person');
|
||||||
}
|
}
|
||||||
|
|
||||||
const finger = await webFinger(id, verifier);
|
const [followersCount = 0, followingCount = 0, postsCount = 0, finger] = await Promise.all([
|
||||||
|
resolver.resolve(object.followers).then(
|
||||||
|
resolved => isCollectionOrOrderedCollection(resolved) ? resolved.totalItems : undefined,
|
||||||
|
() => undefined
|
||||||
|
),
|
||||||
|
resolver.resolve(object.following).then(
|
||||||
|
resolved => isCollectionOrOrderedCollection(resolved) ? resolved.totalItems : undefined,
|
||||||
|
() => undefined
|
||||||
|
),
|
||||||
|
resolver.resolve(object.outbox).then(
|
||||||
|
resolved => isCollectionOrOrderedCollection(resolved) ? resolved.totalItems : undefined,
|
||||||
|
() => undefined
|
||||||
|
),
|
||||||
|
webFinger(id, verifier)
|
||||||
|
]);
|
||||||
|
|
||||||
const host = toUnicode(finger.subject.replace(/^.*?@/, ''));
|
const host = toUnicode(finger.subject.replace(/^.*?@/, ''));
|
||||||
const hostLower = host.replace(/[A-Z]+/, matched => matched.toLowerCase());
|
const hostLower = host.replace(/[A-Z]+/, matched => matched.toLowerCase());
|
||||||
|
@ -42,10 +57,10 @@ export default async (value, verifier?: string) => {
|
||||||
bannerId: null,
|
bannerId: null,
|
||||||
createdAt: Date.parse(object.published) || null,
|
createdAt: Date.parse(object.published) || null,
|
||||||
description: summaryDOM.textContent,
|
description: summaryDOM.textContent,
|
||||||
followersCount: 0,
|
followersCount,
|
||||||
followingCount: 0,
|
followingCount,
|
||||||
|
postsCount,
|
||||||
name: object.name,
|
name: object.name,
|
||||||
postsCount: 0,
|
|
||||||
driveCapacity: 1024 * 1024 * 8, // 8MiB
|
driveCapacity: 1024 * 1024 * 8, // 8MiB
|
||||||
username: object.preferredUsername,
|
username: object.preferredUsername,
|
||||||
usernameLower: object.preferredUsername.toLowerCase(),
|
usernameLower: object.preferredUsername.toLowerCase(),
|
||||||
|
@ -61,18 +76,14 @@ export default async (value, verifier?: string) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [avatarId, bannerId] = await Promise.all([
|
const [avatarId, bannerId] = (await Promise.all([
|
||||||
object.icon,
|
object.icon,
|
||||||
object.image
|
object.image
|
||||||
].map(async img => {
|
].map(img =>
|
||||||
if (img === undefined) {
|
img == null
|
||||||
return null;
|
? Promise.resolve(null)
|
||||||
}
|
: uploadFromUrl(img.url, user)
|
||||||
|
))).map(file => file != null ? file._id : null);
|
||||||
const file = await uploadFromUrl(img.url, user);
|
|
||||||
|
|
||||||
return file._id;
|
|
||||||
}));
|
|
||||||
|
|
||||||
User.update({ _id: user._id }, { $set: { avatarId, bannerId } });
|
User.update({ _id: user._id }, { $set: { avatarId, bannerId } });
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,32 @@
|
||||||
export type IObject = {
|
export type Object = { [x: string]: any };
|
||||||
|
|
||||||
|
export type ActivityType =
|
||||||
|
'Create';
|
||||||
|
|
||||||
|
export interface IObject {
|
||||||
|
'@context': string | object | any[];
|
||||||
type: string;
|
type: string;
|
||||||
};
|
id?: string;
|
||||||
|
summary?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ICollection extends IObject {
|
||||||
|
type: 'Collection';
|
||||||
|
totalItems: number;
|
||||||
|
items: IObject | string | IObject[] | string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IOrderedCollection extends IObject {
|
||||||
|
type: 'OrderedCollection';
|
||||||
|
totalItems: number;
|
||||||
|
orderedItems: IObject | string | IObject[] | string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isCollection = (object: IObject): object is ICollection =>
|
||||||
|
object.type === 'Collection';
|
||||||
|
|
||||||
|
export const isOrderedCollection = (object: IObject): object is IOrderedCollection =>
|
||||||
|
object.type === 'OrderedCollection';
|
||||||
|
|
||||||
|
export const isCollectionOrOrderedCollection = (object: IObject): object is ICollection | IOrderedCollection =>
|
||||||
|
isCollection(object) || isOrderedCollection(object);
|
||||||
|
|
Loading…
Reference in a new issue