forked from Mirrors/doipjs
feat: better support both Person and Note data
This commit is contained in:
parent
75ec28b618
commit
3df1bc7106
2 changed files with 19 additions and 3 deletions
|
@ -270,7 +270,7 @@ export class Claim {
|
|||
const def = _data[claimData.about.id]
|
||||
if (def.functions?.postprocess) {
|
||||
try {
|
||||
({ claimData, proofData } = def.functions.postprocess(claimData, proofData))
|
||||
({ claimData, proofData } = await def.functions.postprocess(claimData, proofData, opts))
|
||||
} catch (_) {}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
import * as E from '../enums.js'
|
||||
import { activitypub } from '../fetcher/index.js'
|
||||
import { ServiceProvider } from '../serviceProvider.js'
|
||||
|
||||
export const reURI = /^https:\/\/(.*)\/?/
|
||||
|
@ -76,8 +77,23 @@ export function processURI (uri) {
|
|||
}
|
||||
|
||||
export const functions = {
|
||||
postprocess: (claimData, proofData) => {
|
||||
postprocess: async (/** @type {ServiceProvider} */ claimData, proofData, opts) => {
|
||||
switch (proofData.result.type) {
|
||||
case 'Note': {
|
||||
claimData.profile.uri = proofData.result.attributedTo
|
||||
const personData = await activitypub.fn({ url: proofData.result.attributedTo }, opts)
|
||||
claimData.profile.display = `@${personData.preferredUsername}@${new URL(proofData.result.url).hostname}`
|
||||
break
|
||||
}
|
||||
|
||||
case 'Person':
|
||||
claimData.profile.display = `@${proofData.result.preferredUsername}@${new URL(proofData.result.url).hostname}`
|
||||
break
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
return { claimData, proofData }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue