mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Refactoring + fixes
This commit is contained in:
parent
b76de03e28
commit
14a57d1ebf
@ -12,12 +12,13 @@ import cluster from 'cluster'
|
||||
import os from 'os'
|
||||
import request from 'request'
|
||||
import as from 'activitystrea.ms'
|
||||
import NitroDatasource from './NitroDatasource'
|
||||
import NitroDataSource from './NitroDataSource'
|
||||
import router from './routes'
|
||||
import dotenv from 'dotenv'
|
||||
import express from 'express'
|
||||
import http from 'http'
|
||||
import { resolve } from 'path'
|
||||
import Collections from './Collections'
|
||||
const debug = require('debug')('ea')
|
||||
const numCPUs = os.cpus().length
|
||||
|
||||
@ -29,7 +30,8 @@ export default class ActivityPub {
|
||||
constructor (domain, port) {
|
||||
if (domain === 'localhost') { this.domain = `${domain}:${port}` } else { this.domain = domain }
|
||||
this.port = port
|
||||
this.dataSource = new NitroDatasource(this.domain)
|
||||
this.dataSource = new NitroDataSource(this.domain)
|
||||
this.collections = new Collections(this.dataSource)
|
||||
}
|
||||
static init (server) {
|
||||
if (!activityPub) {
|
||||
@ -43,6 +45,7 @@ export default class ActivityPub {
|
||||
server.express.use(router)
|
||||
debug('ActivityPub middleware added to the express service')
|
||||
} else {
|
||||
// standalone clustered ActivityPub service
|
||||
if (cluster.isMaster) {
|
||||
debug(`master with pid = ${process.pid} is running`)
|
||||
for (let i = 0; i < numCPUs; i++) {
|
||||
@ -52,7 +55,6 @@ export default class ActivityPub {
|
||||
debug(`worker ${worker.process.pid} died with code ${code} and signal ${signal}`)
|
||||
})
|
||||
} else {
|
||||
// Standalone
|
||||
const app = express()
|
||||
app.set('ap', activityPub)
|
||||
app.use(router)
|
||||
@ -66,30 +68,6 @@ export default class ActivityPub {
|
||||
}
|
||||
}
|
||||
|
||||
getFollowersCollection (actorId) {
|
||||
return this.dataSource.getFollowersCollection(actorId)
|
||||
}
|
||||
|
||||
getFollowersCollectionPage (actorId) {
|
||||
return this.dataSource.getFollowersCollectionPage(actorId)
|
||||
}
|
||||
|
||||
getFollowingCollection (actorId) {
|
||||
return this.dataSource.getFollowingCollection(actorId)
|
||||
}
|
||||
|
||||
getFollowingCollectionPage (actorId) {
|
||||
return this.dataSource.getFollowingCollectionPage(actorId)
|
||||
}
|
||||
|
||||
getOutboxCollection (actorId) {
|
||||
return this.dataSource.getOutboxCollection(actorId)
|
||||
}
|
||||
|
||||
getOutboxCollectionPage (actorId) {
|
||||
return this.dataSource.getOutboxCollectionPage(actorId)
|
||||
}
|
||||
|
||||
handleFollowActivity (activity) {
|
||||
debug(`inside FOLLOW ${activity.actor}`)
|
||||
let toActorName = extractNameFromId(activity.object)
|
||||
@ -191,10 +169,12 @@ export default class ActivityPub {
|
||||
}
|
||||
|
||||
handleLikeActivity (activity) {
|
||||
// TODO differ if activity is an Article/Note/etc.
|
||||
return this.dataSource.createShouted(activity)
|
||||
}
|
||||
|
||||
handleDislikeActivity (activity) {
|
||||
// TODO differ if activity is an Article/Note/etc.
|
||||
return this.dataSource.deleteShouted(activity)
|
||||
}
|
||||
|
||||
|
||||
28
src/activitypub/Collections.js
Normal file
28
src/activitypub/Collections.js
Normal file
@ -0,0 +1,28 @@
|
||||
export default class Collections {
|
||||
constructor (dataSource) {
|
||||
this.dataSource = dataSource
|
||||
}
|
||||
getFollowersCollection (actorId) {
|
||||
return this.dataSource.getFollowersCollection(actorId)
|
||||
}
|
||||
|
||||
getFollowersCollectionPage (actorId) {
|
||||
return this.dataSource.getFollowersCollectionPage(actorId)
|
||||
}
|
||||
|
||||
getFollowingCollection (actorId) {
|
||||
return this.dataSource.getFollowingCollection(actorId)
|
||||
}
|
||||
|
||||
getFollowingCollectionPage (actorId) {
|
||||
return this.dataSource.getFollowingCollectionPage(actorId)
|
||||
}
|
||||
|
||||
getOutboxCollection (actorId) {
|
||||
return this.dataSource.getOutboxCollection(actorId)
|
||||
}
|
||||
|
||||
getOutboxCollectionPage (actorId) {
|
||||
return this.dataSource.getOutboxCollectionPage(actorId)
|
||||
}
|
||||
}
|
||||
@ -28,7 +28,7 @@ const debug = require('debug')('ea:nitro-datasource')
|
||||
|
||||
dotenv.config({ path: resolve('src', 'activitypub', '.env') })
|
||||
|
||||
export default class NitroDatasource {
|
||||
export default class NitroDataSource {
|
||||
constructor (domain) {
|
||||
this.domain = domain
|
||||
const defaultOptions = {
|
||||
@ -30,27 +30,27 @@ export function sendCollection (collectionName, req, res) {
|
||||
|
||||
switch (collectionName) {
|
||||
case 'followers':
|
||||
attachThenCatch(activityPub.getFollowersCollection(id), res)
|
||||
attachThenCatch(activityPub.collections.getFollowersCollection(id), res)
|
||||
break
|
||||
|
||||
case 'followersPage':
|
||||
attachThenCatch(activityPub.getFollowersCollectionPage(id), res)
|
||||
attachThenCatch(activityPub.collections.getFollowersCollectionPage(id), res)
|
||||
break
|
||||
|
||||
case 'following':
|
||||
attachThenCatch(activityPub.getFollowingCollection(id), res)
|
||||
attachThenCatch(activityPub.collections.getFollowingCollection(id), res)
|
||||
break
|
||||
|
||||
case 'followingPage':
|
||||
attachThenCatch(activityPub.getFollowingCollectionPage(id), res)
|
||||
attachThenCatch(activityPub.collections.getFollowingCollectionPage(id), res)
|
||||
break
|
||||
|
||||
case 'outbox':
|
||||
attachThenCatch(activityPub.getOutboxCollection(id), res)
|
||||
attachThenCatch(activityPub.collections.getOutboxCollection(id), res)
|
||||
break
|
||||
|
||||
case 'outboxPage':
|
||||
attachThenCatch(activityPub.getOutboxCollectionPage(id), res)
|
||||
attachThenCatch(activityPub.collections.getOutboxCollectionPage(id), res)
|
||||
break
|
||||
|
||||
default:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user