Validate Note on createNote (#4881)
This commit is contained in:
parent
cc24ce5d1f
commit
ab46232d59
1 changed files with 26 additions and 2 deletions
|
@ -25,6 +25,28 @@ import { ensure } from '../../../prelude/ensure';
|
||||||
|
|
||||||
const logger = apLogger;
|
const logger = apLogger;
|
||||||
|
|
||||||
|
export function validateNote(object: any, uri: string) {
|
||||||
|
const expectHost = extractDbHost(uri);
|
||||||
|
|
||||||
|
if (object == null) {
|
||||||
|
return new Error('invalid Note: object is null');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!['Note', 'Question', 'Article'].includes(object.type)) {
|
||||||
|
return new Error(`invalid Note: invalied object type ${object.type}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object.id && extractDbHost(object.id) !== expectHost) {
|
||||||
|
return new Error(`invalid Note: id has different host. expected: ${expectHost}, actual: ${extractDbHost(object.id)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object.attributedTo && extractDbHost(object.attributedTo) !== expectHost) {
|
||||||
|
return new Error(`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${extractDbHost(object.attributedTo)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Noteをフェッチします。
|
* Noteをフェッチします。
|
||||||
*
|
*
|
||||||
|
@ -59,8 +81,10 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
|
||||||
|
|
||||||
const object: any = await resolver.resolve(value);
|
const object: any = await resolver.resolve(value);
|
||||||
|
|
||||||
if (!object || !['Note', 'Question', 'Article'].includes(object.type)) {
|
const entryUri = value.id || value;
|
||||||
logger.error(`invalid note: ${value}`, {
|
const err = validateNote(object, entryUri);
|
||||||
|
if (err) {
|
||||||
|
logger.error(`${err.message}`, {
|
||||||
resolver: {
|
resolver: {
|
||||||
history: resolver.getHistory()
|
history: resolver.getHistory()
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue