mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 22:49:28 -07:00
feat: better support both Person and Note data
This commit is contained in:
parent
09b052c7b9
commit
cb841fe9b7
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