mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 17:43:09 +02:00
wip
This commit is contained in:
parent
fd73fad148
commit
fba46b4c7f
3 changed files with 15 additions and 60 deletions
|
@ -1,17 +1,11 @@
|
||||||
import deliverPost from './deliver-post';
|
import deliver from './deliver';
|
||||||
import follow from './follow';
|
|
||||||
import performActivityPub from './perform-activitypub';
|
|
||||||
import processInbox from './process-inbox';
|
import processInbox from './process-inbox';
|
||||||
import reportGitHubFailure from './report-github-failure';
|
import reportGitHubFailure from './report-github-failure';
|
||||||
import unfollow from './unfollow';
|
|
||||||
|
|
||||||
const handlers = {
|
const handlers = {
|
||||||
deliverPost,
|
deliver,
|
||||||
follow,
|
|
||||||
performActivityPub,
|
|
||||||
processInbox,
|
processInbox,
|
||||||
reportGitHubFailure,
|
reportGitHubFailure,
|
||||||
unfollow
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (job, done) => handlers[job.data.type](job).then(() => done(), done);
|
export default (job, done) => handlers[job.data.type](job).then(() => done(), done);
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
import User from '../../models/user';
|
|
||||||
import act from '../../remote/activitypub/act';
|
|
||||||
import Resolver from '../../remote/activitypub/resolver';
|
|
||||||
|
|
||||||
export default ({ data }) => User.findOne({ _id: data.actor })
|
|
||||||
.then(actor => act(new Resolver(), actor, data.outbox))
|
|
||||||
.then(Promise.all);
|
|
|
@ -1,17 +1,15 @@
|
||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
import { toUnicode } from 'punycode';
|
import { toUnicode } from 'punycode';
|
||||||
import User, { validateUsername, isValidName, isValidDescription } from '../../models/user';
|
import User, { validateUsername, isValidName, isValidDescription } from '../../models/user';
|
||||||
import queue from '../../queue';
|
|
||||||
import webFinger from '../webfinger';
|
import webFinger from '../webfinger';
|
||||||
import create from './create';
|
import create from './create';
|
||||||
import Resolver from './resolver';
|
import Resolver from './resolver';
|
||||||
|
import uploadFromUrl from '../../api/drive/upload-from-url';
|
||||||
async function isCollection(collection) {
|
|
||||||
return ['Collection', 'OrderedCollection'].includes(collection.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async (value, verifier?: string) => {
|
export default async (value, verifier?: string) => {
|
||||||
const { resolver, object } = await new Resolver().resolveOne(value);
|
const resolver = new Resolver();
|
||||||
|
|
||||||
|
const object = await resolver.resolve(value) as any;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
object === null ||
|
object === null ||
|
||||||
|
@ -21,24 +19,10 @@ export default async (value, verifier?: string) => {
|
||||||
!isValidName(object.name) ||
|
!isValidName(object.name) ||
|
||||||
!isValidDescription(object.summary)
|
!isValidDescription(object.summary)
|
||||||
) {
|
) {
|
||||||
throw new Error();
|
throw new Error('invalid person');
|
||||||
}
|
}
|
||||||
|
|
||||||
const [followers, following, outbox, finger] = await Promise.all([
|
const finger = await webFinger(object.id, verifier);
|
||||||
resolver.resolveOne(object.followers).then(
|
|
||||||
resolved => isCollection(resolved.object) ? resolved.object : null,
|
|
||||||
() => null
|
|
||||||
),
|
|
||||||
resolver.resolveOne(object.following).then(
|
|
||||||
resolved => isCollection(resolved.object) ? resolved.object : null,
|
|
||||||
() => null
|
|
||||||
),
|
|
||||||
resolver.resolveOne(object.outbox).then(
|
|
||||||
resolved => isCollection(resolved.object) ? resolved.object : null,
|
|
||||||
() => null
|
|
||||||
),
|
|
||||||
webFinger(object.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());
|
||||||
|
@ -50,10 +34,10 @@ export default async (value, verifier?: string) => {
|
||||||
bannerId: null,
|
bannerId: null,
|
||||||
createdAt: Date.parse(object.published),
|
createdAt: Date.parse(object.published),
|
||||||
description: summaryDOM.textContent,
|
description: summaryDOM.textContent,
|
||||||
followersCount: followers ? followers.totalItem || 0 : 0,
|
followersCount: 0,
|
||||||
followingCount: following ? following.totalItem || 0 : 0,
|
followingCount: 0,
|
||||||
name: object.name,
|
name: object.name,
|
||||||
postsCount: outbox ? outbox.totalItem || 0 : 0,
|
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(),
|
||||||
|
@ -69,33 +53,17 @@ export default async (value, verifier?: string) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
queue.create('http', {
|
|
||||||
type: 'performActivityPub',
|
|
||||||
actor: user._id,
|
|
||||||
outbox
|
|
||||||
}).save();
|
|
||||||
|
|
||||||
const [avatarId, bannerId] = await Promise.all([
|
const [avatarId, bannerId] = await Promise.all([
|
||||||
object.icon,
|
object.icon,
|
||||||
object.image
|
object.image
|
||||||
].map(async value => {
|
].map(async url => {
|
||||||
if (value === undefined) {
|
if (url === undefined) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const img = await uploadFromUrl(url, user);
|
||||||
const created = await create(resolver, user, value);
|
|
||||||
|
|
||||||
await Promise.all(created.map(asyncCreated => asyncCreated.then(created => {
|
return img._id;
|
||||||
if (created !== null && created.object.$ref === 'driveFiles.files') {
|
|
||||||
throw created.object.$id;
|
|
||||||
}
|
|
||||||
}, () => {})));
|
|
||||||
|
|
||||||
return null;
|
|
||||||
} catch (id) {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
User.update({ _id: user._id }, { $set: { avatarId, bannerId } });
|
User.update({ _id: user._id }, { $set: { avatarId, bannerId } });
|
||||||
|
|
Loading…
Reference in a new issue