merge: Reduce log spam (!1004)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1004 Approved-by: dakkar <dakkar@thenautilus.net> Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
commit
00c0bdbc94
113 changed files with 909 additions and 626 deletions
|
|
@ -13,6 +13,7 @@ import { QueueService } from '@/core/QueueService.js';
|
|||
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
||||
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
||||
import { SystemAccountService } from '@/core/SystemAccountService.js';
|
||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||
import { IdService } from './IdService.js';
|
||||
|
||||
@Injectable()
|
||||
|
|
@ -125,11 +126,11 @@ export class AbuseReportService {
|
|||
const report = await this.abuseUserReportsRepository.findOneByOrFail({ id: reportId });
|
||||
|
||||
if (report.targetUserHost == null) {
|
||||
throw new Error('The target user host is null.');
|
||||
throw new IdentifiableError('0b1ce202-b2c1-4ee4-8af4-2742a51b383d', 'The target user host is null.');
|
||||
}
|
||||
|
||||
if (report.forwarded) {
|
||||
throw new Error('The report has already been forwarded.');
|
||||
throw new IdentifiableError('5c008bdf-f0e8-4154-9f34-804e114516d7', 'The report has already been forwarded.');
|
||||
}
|
||||
|
||||
await this.abuseUserReportsRepository.update(report.id, {
|
||||
|
|
|
|||
|
|
@ -80,15 +80,15 @@ export class BunnyService {
|
|||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
this.bunnyCdnLogger.error(error);
|
||||
this.bunnyCdnLogger.error('Unhandled error', error);
|
||||
data.destroy();
|
||||
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140bf91', 'An error has occured during the connectiong to BunnyCDN');
|
||||
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140bf91', 'An error has occurred while connecting to BunnyCDN', true, error);
|
||||
});
|
||||
|
||||
data.pipe(req).on('finish', () => {
|
||||
data.destroy();
|
||||
});
|
||||
|
||||
|
||||
// wait till stream gets destroyed upon finish of piping to prevent the UI from showing the upload as success way too early
|
||||
await finished(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ export class CaptchaError extends Error {
|
|||
public readonly cause?: unknown;
|
||||
|
||||
constructor(code: CaptchaErrorCode, message: string, cause?: unknown) {
|
||||
super(message);
|
||||
super(message, cause ? { cause } : undefined);
|
||||
this.code = code;
|
||||
this.cause = cause;
|
||||
this.name = 'CaptchaError';
|
||||
|
|
@ -117,7 +117,7 @@ export class CaptchaService {
|
|||
}
|
||||
|
||||
const result = await this.getCaptchaResponse('https://www.recaptcha.net/recaptcha/api/siteverify', secret, response).catch(err => {
|
||||
throw new CaptchaError(captchaErrorCodes.requestFailed, `recaptcha-request-failed: ${err}`);
|
||||
throw new CaptchaError(captchaErrorCodes.requestFailed, `recaptcha-request-failed: ${err}`, err);
|
||||
});
|
||||
|
||||
if (result.success !== true) {
|
||||
|
|
@ -133,7 +133,7 @@ export class CaptchaService {
|
|||
}
|
||||
|
||||
const result = await this.getCaptchaResponse('https://hcaptcha.com/siteverify', secret, response).catch(err => {
|
||||
throw new CaptchaError(captchaErrorCodes.requestFailed, `hcaptcha-request-failed: ${err}`);
|
||||
throw new CaptchaError(captchaErrorCodes.requestFailed, `hcaptcha-request-failed: ${err}`, err);
|
||||
});
|
||||
|
||||
if (result.success !== true) {
|
||||
|
|
@ -209,7 +209,7 @@ export class CaptchaService {
|
|||
}
|
||||
|
||||
const result = await this.getCaptchaResponse('https://challenges.cloudflare.com/turnstile/v0/siteverify', secret, response).catch(err => {
|
||||
throw new CaptchaError(captchaErrorCodes.requestFailed, `turnstile-request-failed: ${err}`);
|
||||
throw new CaptchaError(captchaErrorCodes.requestFailed, `turnstile-request-failed: ${err}`, err);
|
||||
});
|
||||
|
||||
if (result.success !== true) {
|
||||
|
|
@ -386,7 +386,7 @@ export class CaptchaService {
|
|||
this.logger.info(err);
|
||||
const error = err instanceof CaptchaError
|
||||
? err
|
||||
: new CaptchaError(captchaErrorCodes.unknown, `unknown error: ${err}`);
|
||||
: new CaptchaError(captchaErrorCodes.unknown, `unknown error: ${err}`, err);
|
||||
return {
|
||||
success: false,
|
||||
error,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import { LoggerService } from '@/core/LoggerService.js';
|
|||
import type Logger from '@/logger.js';
|
||||
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { renderInlineError } from '@/misc/render-inline-error.js';
|
||||
|
||||
@Injectable()
|
||||
export class DownloadService {
|
||||
|
|
@ -37,7 +38,7 @@ export class DownloadService {
|
|||
public async downloadUrl(url: string, path: string, options: { timeout?: number, operationTimeout?: number, maxSize?: number } = {} ): Promise<{
|
||||
filename: string;
|
||||
}> {
|
||||
this.logger.info(`Downloading ${chalk.cyan(url)} to ${chalk.cyanBright(path)} ...`);
|
||||
this.logger.debug(`Downloading ${chalk.cyan(url)} to ${chalk.cyanBright(path)} ...`);
|
||||
|
||||
const timeout = options.timeout ?? 30 * 1000;
|
||||
const operationTimeout = options.operationTimeout ?? 60 * 1000;
|
||||
|
|
@ -86,7 +87,7 @@ export class DownloadService {
|
|||
filename = parsed.parameters.filename;
|
||||
}
|
||||
} catch (e) {
|
||||
this.logger.warn(`Failed to parse content-disposition: ${contentDisposition}`, { stack: e });
|
||||
this.logger.warn(`Failed to parse content-disposition ${contentDisposition}: ${renderInlineError(e)}`);
|
||||
}
|
||||
}
|
||||
}).on('downloadProgress', (progress: Got.Progress) => {
|
||||
|
|
@ -100,13 +101,17 @@ export class DownloadService {
|
|||
await stream.pipeline(req, fs.createWriteStream(path));
|
||||
} catch (e) {
|
||||
if (e instanceof Got.HTTPError) {
|
||||
throw new StatusError(`${e.response.statusCode} ${e.response.statusMessage}`, e.response.statusCode, e.response.statusMessage);
|
||||
} else {
|
||||
throw new StatusError(`download error from ${url}`, e.response.statusCode, e.response.statusMessage, e);
|
||||
} else if (e instanceof Got.RequestError || e instanceof Got.AbortError) {
|
||||
throw new Error(String(e), { cause: e });
|
||||
} else if (e instanceof Error) {
|
||||
throw e;
|
||||
} else {
|
||||
throw new Error(String(e), { cause: e });
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.succ(`Download finished: ${chalk.cyan(url)}`);
|
||||
this.logger.info(`Download finished: ${chalk.cyan(url)}`);
|
||||
|
||||
return {
|
||||
filename,
|
||||
|
|
@ -118,7 +123,7 @@ export class DownloadService {
|
|||
// Create temp file
|
||||
const [path, cleanup] = await createTemp();
|
||||
|
||||
this.logger.info(`text file: Temp file is ${path}`);
|
||||
this.logger.debug(`text file: Temp file is ${path}`);
|
||||
|
||||
try {
|
||||
// write content at URL to temp file
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import { isMimeImage } from '@/misc/is-mime-image.js';
|
|||
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
||||
import { UtilityService } from '@/core/UtilityService.js';
|
||||
import { BunnyService } from '@/core/BunnyService.js';
|
||||
import { renderInlineError } from '@/misc/render-inline-error.js';
|
||||
import { LoggerService } from './LoggerService.js';
|
||||
|
||||
type AddFileArgs = {
|
||||
|
|
@ -202,7 +203,7 @@ export class DriveService {
|
|||
//#endregion
|
||||
|
||||
//#region Uploads
|
||||
this.registerLogger.info(`uploading original: ${key}`);
|
||||
this.registerLogger.debug(`uploading original: ${key}`);
|
||||
const uploads = [
|
||||
this.upload(key, fs.createReadStream(path), type, null, name),
|
||||
];
|
||||
|
|
@ -211,7 +212,7 @@ export class DriveService {
|
|||
webpublicKey = `${prefix}webpublic-${randomUUID()}.${alts.webpublic.ext}`;
|
||||
webpublicUrl = `${ baseUrl }/${ webpublicKey }`;
|
||||
|
||||
this.registerLogger.info(`uploading webpublic: ${webpublicKey}`);
|
||||
this.registerLogger.debug(`uploading webpublic: ${webpublicKey}`);
|
||||
uploads.push(this.upload(webpublicKey, alts.webpublic.data, alts.webpublic.type, alts.webpublic.ext, name));
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +220,7 @@ export class DriveService {
|
|||
thumbnailKey = `${prefix}thumbnail-${randomUUID()}.${alts.thumbnail.ext}`;
|
||||
thumbnailUrl = `${ baseUrl }/${ thumbnailKey }`;
|
||||
|
||||
this.registerLogger.info(`uploading thumbnail: ${thumbnailKey}`);
|
||||
this.registerLogger.debug(`uploading thumbnail: ${thumbnailKey}`);
|
||||
uploads.push(this.upload(thumbnailKey, alts.thumbnail.data, alts.thumbnail.type, alts.thumbnail.ext, `${name}.thumbnail`));
|
||||
}
|
||||
|
||||
|
|
@ -263,11 +264,11 @@ export class DriveService {
|
|||
const [url, thumbnailUrl, webpublicUrl] = await Promise.all(promises);
|
||||
|
||||
if (thumbnailUrl) {
|
||||
this.registerLogger.info(`thumbnail stored: ${thumbnailAccessKey}`);
|
||||
this.registerLogger.debug(`thumbnail stored: ${thumbnailAccessKey}`);
|
||||
}
|
||||
|
||||
if (webpublicUrl) {
|
||||
this.registerLogger.info(`web stored: ${webpublicAccessKey}`);
|
||||
this.registerLogger.debug(`web stored: ${webpublicAccessKey}`);
|
||||
}
|
||||
|
||||
file.storedInternal = true;
|
||||
|
|
@ -311,7 +312,7 @@ export class DriveService {
|
|||
thumbnail,
|
||||
};
|
||||
} catch (err) {
|
||||
this.registerLogger.warn(`GenerateVideoThumbnail failed: ${err}`);
|
||||
this.registerLogger.warn(`GenerateVideoThumbnail failed: ${renderInlineError(err)}`);
|
||||
return {
|
||||
webpublic: null,
|
||||
thumbnail: null,
|
||||
|
|
@ -344,7 +345,7 @@ export class DriveService {
|
|||
metadata.height && metadata.height <= 2048
|
||||
);
|
||||
} catch (err) {
|
||||
this.registerLogger.warn(`sharp failed: ${err}`);
|
||||
this.registerLogger.warn(`sharp failed: ${renderInlineError(err)}`);
|
||||
return {
|
||||
webpublic: null,
|
||||
thumbnail: null,
|
||||
|
|
@ -355,7 +356,7 @@ export class DriveService {
|
|||
let webpublic: IImage | null = null;
|
||||
|
||||
if (generateWeb && !satisfyWebpublic && !isAnimated) {
|
||||
this.registerLogger.info('creating web image');
|
||||
this.registerLogger.debug('creating web image');
|
||||
|
||||
try {
|
||||
if (['image/jpeg', 'image/webp', 'image/avif'].includes(type)) {
|
||||
|
|
@ -369,9 +370,9 @@ export class DriveService {
|
|||
this.registerLogger.warn('web image not created (an error occurred)', err as Error);
|
||||
}
|
||||
} else {
|
||||
if (satisfyWebpublic) this.registerLogger.info('web image not created (original satisfies webpublic)');
|
||||
else if (isAnimated) this.registerLogger.info('web image not created (animated image)');
|
||||
else this.registerLogger.info('web image not created (from remote)');
|
||||
if (satisfyWebpublic) this.registerLogger.debug('web image not created (original satisfies webpublic)');
|
||||
else if (isAnimated) this.registerLogger.debug('web image not created (animated image)');
|
||||
else this.registerLogger.debug('web image not created (from remote)');
|
||||
}
|
||||
// #endregion webpublic
|
||||
|
||||
|
|
@ -498,7 +499,6 @@ export class DriveService {
|
|||
}: AddFileArgs): Promise<MiDriveFile> {
|
||||
const userRoleNSFW = user && (await this.roleService.getUserPolicies(user.id)).alwaysMarkNsfw;
|
||||
const info = await this.fileInfoService.getFileInfo(path);
|
||||
this.registerLogger.info(`${JSON.stringify(info)}`);
|
||||
|
||||
// detect name
|
||||
const detectedName = correctFilename(
|
||||
|
|
@ -508,6 +508,8 @@ export class DriveService {
|
|||
ext ?? info.type.ext,
|
||||
);
|
||||
|
||||
this.registerLogger.debug(`Detected file info: ${JSON.stringify(info)}`);
|
||||
|
||||
if (user && !force) {
|
||||
// Check if there is a file with the same hash
|
||||
const matched = await this.driveFilesRepository.findOneBy({
|
||||
|
|
@ -516,7 +518,7 @@ export class DriveService {
|
|||
});
|
||||
|
||||
if (matched) {
|
||||
this.registerLogger.info(`file with same hash is found: ${matched.id}`);
|
||||
this.registerLogger.debug(`file with same hash is found: ${matched.id}`);
|
||||
if (sensitive && !matched.isSensitive) {
|
||||
// The file is federated as sensitive for this time, but was federated as non-sensitive before.
|
||||
// Therefore, update the file to sensitive.
|
||||
|
|
@ -644,14 +646,14 @@ export class DriveService {
|
|||
} catch (err) {
|
||||
// duplicate key error (when already registered)
|
||||
if (isDuplicateKeyValueError(err)) {
|
||||
this.registerLogger.info(`already registered ${file.uri}`);
|
||||
this.registerLogger.debug(`already registered ${file.uri}`);
|
||||
|
||||
file = await this.driveFilesRepository.findOneBy({
|
||||
uri: file.uri!,
|
||||
userId: user ? user.id : IsNull(),
|
||||
}) as MiDriveFile;
|
||||
} else {
|
||||
this.registerLogger.error(err as Error);
|
||||
this.registerLogger.error('Error in drive register', err as Error);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
|
@ -659,7 +661,7 @@ export class DriveService {
|
|||
file = await (this.save(file, path, detectedName, info));
|
||||
}
|
||||
|
||||
this.registerLogger.succ(`drive file has been created ${file.id}`);
|
||||
this.registerLogger.info(`Created file ${file.id} (${detectedName}) of type ${info.type.mime} for user ${user?.id ?? '<none>'}`);
|
||||
|
||||
if (user) {
|
||||
this.driveFileEntityService.pack(file, { self: true }).then(packedFile => {
|
||||
|
|
@ -892,13 +894,10 @@ export class DriveService {
|
|||
}
|
||||
|
||||
const driveFile = await this.addFile({ user, path, name, comment, folderId, force, isLink, url, uri, sensitive, requestIp, requestHeaders });
|
||||
this.downloaderLogger.succ(`Got: ${driveFile.id}`);
|
||||
this.downloaderLogger.debug(`Upload succeeded: created file ${driveFile.id}`);
|
||||
return driveFile!;
|
||||
} catch (err) {
|
||||
this.downloaderLogger.error(`Failed to create drive file: ${err}`, {
|
||||
url: url,
|
||||
e: err,
|
||||
});
|
||||
this.downloaderLogger.error(`Failed to create drive file from ${url}: ${renderInlineError(err)}`);
|
||||
throw err;
|
||||
} finally {
|
||||
cleanup();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import { LoggerService } from '@/core/LoggerService.js';
|
|||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
|
||||
import { renderInlineError } from '@/misc/render-inline-error.js';
|
||||
import type { CheerioAPI } from 'cheerio';
|
||||
|
||||
type NodeInfo = {
|
||||
|
|
@ -90,7 +91,7 @@ export class FetchInstanceMetadataService {
|
|||
}
|
||||
}
|
||||
|
||||
this.logger.info(`Fetching metadata of ${instance.host} ...`);
|
||||
this.logger.debug(`Fetching metadata of ${instance.host} ...`);
|
||||
|
||||
const [info, dom, manifest] = await Promise.all([
|
||||
this.fetchNodeinfo(instance).catch(() => null),
|
||||
|
|
@ -106,7 +107,7 @@ export class FetchInstanceMetadataService {
|
|||
this.getDescription(info, dom, manifest).catch(() => null),
|
||||
]);
|
||||
|
||||
this.logger.succ(`Successfuly fetched metadata of ${instance.host}`);
|
||||
this.logger.debug(`Successfuly fetched metadata of ${instance.host}`);
|
||||
|
||||
const updates = {
|
||||
infoUpdatedAt: new Date(),
|
||||
|
|
@ -128,9 +129,9 @@ export class FetchInstanceMetadataService {
|
|||
|
||||
await this.federatedInstanceService.update(instance.id, updates);
|
||||
|
||||
this.logger.succ(`Successfuly updated metadata of ${instance.host}`);
|
||||
this.logger.info(`Successfully updated metadata of ${instance.host}`);
|
||||
} catch (e) {
|
||||
this.logger.error(`Failed to update metadata of ${instance.host}: ${e}`);
|
||||
this.logger.error(`Failed to update metadata of ${instance.host}: ${renderInlineError(e)}`);
|
||||
} finally {
|
||||
await this.unlock(host);
|
||||
}
|
||||
|
|
@ -138,7 +139,7 @@ export class FetchInstanceMetadataService {
|
|||
|
||||
@bindThis
|
||||
private async fetchNodeinfo(instance: MiInstance): Promise<NodeInfo> {
|
||||
this.logger.info(`Fetching nodeinfo of ${instance.host} ...`);
|
||||
this.logger.debug(`Fetching nodeinfo of ${instance.host} ...`);
|
||||
|
||||
try {
|
||||
const wellknown = await this.httpRequestService.getJson('https://' + instance.host + '/.well-known/nodeinfo')
|
||||
|
|
@ -170,11 +171,11 @@ export class FetchInstanceMetadataService {
|
|||
throw err.statusCode ?? err.message;
|
||||
});
|
||||
|
||||
this.logger.succ(`Successfuly fetched nodeinfo of ${instance.host}`);
|
||||
this.logger.debug(`Successfuly fetched nodeinfo of ${instance.host}`);
|
||||
|
||||
return info as NodeInfo;
|
||||
} catch (err) {
|
||||
this.logger.error(`Failed to fetch nodeinfo of ${instance.host}: ${err}`);
|
||||
this.logger.warn(`Failed to fetch nodeinfo of ${instance.host}: ${renderInlineError(err)}`);
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
|
@ -182,7 +183,7 @@ export class FetchInstanceMetadataService {
|
|||
|
||||
@bindThis
|
||||
private async fetchDom(instance: MiInstance): Promise<CheerioAPI> {
|
||||
this.logger.info(`Fetching HTML of ${instance.host} ...`);
|
||||
this.logger.debug(`Fetching HTML of ${instance.host} ...`);
|
||||
|
||||
const url = 'https://' + instance.host;
|
||||
|
||||
|
|
|
|||
|
|
@ -46,11 +46,13 @@ const TYPE_SVG = {
|
|||
@Injectable()
|
||||
export class FileInfoService {
|
||||
private logger: Logger;
|
||||
private ffprobeLogger: Logger;
|
||||
|
||||
constructor(
|
||||
private loggerService: LoggerService,
|
||||
) {
|
||||
this.logger = this.loggerService.getLogger('file-info');
|
||||
this.ffprobeLogger = this.logger.createSubLogger('ffprobe');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -162,20 +164,19 @@ export class FileInfoService {
|
|||
*/
|
||||
@bindThis
|
||||
private hasVideoTrackOnVideoFile(path: string): Promise<boolean> {
|
||||
const sublogger = this.logger.createSubLogger('ffprobe');
|
||||
sublogger.info(`Checking the video file. File path: ${path}`);
|
||||
this.ffprobeLogger.debug(`Checking the video file. File path: ${path}`);
|
||||
return new Promise((resolve) => {
|
||||
try {
|
||||
FFmpeg.ffprobe(path, (err, metadata) => {
|
||||
if (err) {
|
||||
sublogger.warn(`Could not check the video file. Returns true. File path: ${path}`, err);
|
||||
this.ffprobeLogger.warn(`Could not check the video file. Returns true. File path: ${path}`, err);
|
||||
resolve(true);
|
||||
return;
|
||||
}
|
||||
resolve(metadata.streams.some((stream) => stream.codec_type === 'video'));
|
||||
});
|
||||
} catch (err) {
|
||||
sublogger.warn(`Could not check the video file. Returns true. File path: ${path}`, err as Error);
|
||||
this.ffprobeLogger.warn(`Could not check the video file. Returns true. File path: ${path}`, err as Error);
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -331,7 +331,7 @@ export class HttpRequestService {
|
|||
});
|
||||
|
||||
if (!res.ok && extra.throwErrorWhenResponseNotOk) {
|
||||
throw new StatusError(`${res.status} ${res.statusText}`, res.status, res.statusText);
|
||||
throw new StatusError(`request error from ${url}`, res.status, res.statusText);
|
||||
}
|
||||
|
||||
if (res.ok) {
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ export class NoteCreateService implements OnApplicationShutdown {
|
|||
case 'followers':
|
||||
// 他人のfollowers noteはreject
|
||||
if (data.renote.userId !== user.id) {
|
||||
throw new Error('Renote target is not public or home');
|
||||
throw new IdentifiableError('b6352a84-e5cd-4b05-a26c-63437a6b98ba', 'Renote target is not public or home');
|
||||
}
|
||||
|
||||
// Renote対象がfollowersならfollowersにする
|
||||
|
|
@ -304,7 +304,7 @@ export class NoteCreateService implements OnApplicationShutdown {
|
|||
break;
|
||||
case 'specified':
|
||||
// specified / direct noteはreject
|
||||
throw new Error('Renote target is not public or home');
|
||||
throw new IdentifiableError('b6352a84-e5cd-4b05-a26c-63437a6b98ba', 'Renote target is not public or home');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +317,7 @@ export class NoteCreateService implements OnApplicationShutdown {
|
|||
if (data.renote.userId !== user.id) {
|
||||
const blocked = await this.userBlockingService.checkBlocked(data.renote.userId, user.id);
|
||||
if (blocked) {
|
||||
throw new Error('blocked');
|
||||
throw new IdentifiableError('b6352a84-e5cd-4b05-a26c-63437a6b98ba', 'Renote target is blocked');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -489,10 +489,10 @@ export class NoteCreateService implements OnApplicationShutdown {
|
|||
|
||||
// should really not happen, but better safe than sorry
|
||||
if (data.reply?.id === insert.id) {
|
||||
throw new Error('A note can\'t reply to itself');
|
||||
throw new IdentifiableError('ea93b7c2-3d6c-4e10-946b-00d50b1a75cb', 'A note can\'t reply to itself');
|
||||
}
|
||||
if (data.renote?.id === insert.id) {
|
||||
throw new Error('A note can\'t renote itself');
|
||||
throw new IdentifiableError('ea93b7c2-3d6c-4e10-946b-00d50b1a75cb', 'A note can\'t renote itself');
|
||||
}
|
||||
|
||||
if (data.uri != null) insert.uri = data.uri;
|
||||
|
|
@ -549,8 +549,6 @@ export class NoteCreateService implements OnApplicationShutdown {
|
|||
throw err;
|
||||
}
|
||||
|
||||
console.error(e);
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ export class NoteEditService implements OnApplicationShutdown {
|
|||
|
||||
if (this.isRenote(data)) {
|
||||
if (data.renote.id === oldnote.id) {
|
||||
throw new UnrecoverableError(`edit failed for ${oldnote.id}: cannot renote itself`);
|
||||
throw new IdentifiableError('ea93b7c2-3d6c-4e10-946b-00d50b1a75cb', `edit failed for ${oldnote.id}: cannot renote itself`);
|
||||
}
|
||||
|
||||
switch (data.renote.visibility) {
|
||||
|
|
@ -325,7 +325,7 @@ export class NoteEditService implements OnApplicationShutdown {
|
|||
case 'followers':
|
||||
// 他人のfollowers noteはreject
|
||||
if (data.renote.userId !== user.id) {
|
||||
throw new Error('Renote target is not public or home');
|
||||
throw new IdentifiableError('b6352a84-e5cd-4b05-a26c-63437a6b98ba', 'Renote target is not public or home');
|
||||
}
|
||||
|
||||
// Renote対象がfollowersならfollowersにする
|
||||
|
|
@ -333,7 +333,7 @@ export class NoteEditService implements OnApplicationShutdown {
|
|||
break;
|
||||
case 'specified':
|
||||
// specified / direct noteはreject
|
||||
throw new Error('Renote target is not public or home');
|
||||
throw new IdentifiableError('b6352a84-e5cd-4b05-a26c-63437a6b98ba', 'Renote target is not public or home');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ export class NotePiningService {
|
|||
});
|
||||
|
||||
if (note == null) {
|
||||
throw new IdentifiableError('70c4e51f-5bea-449c-a030-53bee3cce202', 'No such note.');
|
||||
throw new IdentifiableError('70c4e51f-5bea-449c-a030-53bee3cce202', `Note ${noteId} does not exist`);
|
||||
}
|
||||
|
||||
await this.db.transaction(async tem => {
|
||||
|
|
@ -102,7 +102,7 @@ export class NotePiningService {
|
|||
});
|
||||
|
||||
if (note == null) {
|
||||
throw new IdentifiableError('b302d4cf-c050-400a-bbb3-be208681f40c', 'No such note.');
|
||||
throw new IdentifiableError('b302d4cf-c050-400a-bbb3-be208681f40c', `Note ${noteId} does not exist`);
|
||||
}
|
||||
|
||||
this.userNotePiningsRepository.delete({
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ export class ReactionService {
|
|||
if (note.userId !== user.id) {
|
||||
const blocked = await this.userBlockingService.checkBlocked(note.userId, user.id);
|
||||
if (blocked) {
|
||||
throw new IdentifiableError('e70412a4-7197-4726-8e74-f3e0deb92aa7');
|
||||
throw new IdentifiableError('e70412a4-7197-4726-8e74-f3e0deb92aa7', 'Note not accessible for you.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -322,14 +322,14 @@ export class ReactionService {
|
|||
});
|
||||
|
||||
if (exist == null) {
|
||||
throw new IdentifiableError('60527ec9-b4cb-4a88-a6bd-32d3ad26817d', 'not reacted');
|
||||
throw new IdentifiableError('60527ec9-b4cb-4a88-a6bd-32d3ad26817d', 'reaction does not exist');
|
||||
}
|
||||
|
||||
// Delete reaction
|
||||
const result = await this.noteReactionsRepository.delete(exist.id);
|
||||
|
||||
if (result.affected !== 1) {
|
||||
throw new IdentifiableError('60527ec9-b4cb-4a88-a6bd-32d3ad26817d', 'not reacted');
|
||||
throw new IdentifiableError('60527ec9-b4cb-4a88-a6bd-32d3ad26817d', 'reaction does not exist');
|
||||
}
|
||||
|
||||
// Decrement reactions count
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { URL } from 'node:url';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import chalk from 'chalk';
|
||||
import { IsNull } from 'typeorm';
|
||||
|
|
@ -18,6 +17,7 @@ import { RemoteLoggerService } from '@/core/RemoteLoggerService.js';
|
|||
import { ApDbResolverService } from '@/core/activitypub/ApDbResolverService.js';
|
||||
import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { renderInlineError } from '@/misc/render-inline-error.js';
|
||||
|
||||
@Injectable()
|
||||
export class RemoteUserResolveService {
|
||||
|
|
@ -44,27 +44,13 @@ export class RemoteUserResolveService {
|
|||
const usernameLower = username.toLowerCase();
|
||||
|
||||
if (host == null) {
|
||||
this.logger.info(`return local user: ${usernameLower}`);
|
||||
return await this.usersRepository.findOneBy({ usernameLower, host: IsNull() }).then(u => {
|
||||
if (u == null) {
|
||||
throw new Error('user not found');
|
||||
} else {
|
||||
return u;
|
||||
}
|
||||
}) as MiLocalUser;
|
||||
return await this.usersRepository.findOneByOrFail({ usernameLower, host: IsNull() }) as MiLocalUser;
|
||||
}
|
||||
|
||||
host = this.utilityService.toPuny(host);
|
||||
|
||||
if (host === this.utilityService.toPuny(this.config.host)) {
|
||||
this.logger.info(`return local user: ${usernameLower}`);
|
||||
return await this.usersRepository.findOneBy({ usernameLower, host: IsNull() }).then(u => {
|
||||
if (u == null) {
|
||||
throw new Error('user not found');
|
||||
} else {
|
||||
return u;
|
||||
}
|
||||
}) as MiLocalUser;
|
||||
return await this.usersRepository.findOneByOrFail({ usernameLower, host: IsNull() }) as MiLocalUser;
|
||||
}
|
||||
|
||||
const user = await this.usersRepository.findOneBy({ usernameLower, host }) as MiRemoteUser | null;
|
||||
|
|
@ -82,7 +68,7 @@ export class RemoteUserResolveService {
|
|||
.getUserFromApId(self.href)
|
||||
.then((u) => {
|
||||
if (u == null) {
|
||||
throw new Error('local user not found');
|
||||
throw new Error(`local user not found: ${self.href}`);
|
||||
} else {
|
||||
return u;
|
||||
}
|
||||
|
|
@ -90,7 +76,7 @@ export class RemoteUserResolveService {
|
|||
}
|
||||
}
|
||||
|
||||
this.logger.succ(`return new remote user: ${chalk.magenta(acctLower)}`);
|
||||
this.logger.info(`Fetching new remote user ${chalk.magenta(acctLower)} from ${self.href}`);
|
||||
return await this.apPersonService.createPerson(self.href);
|
||||
}
|
||||
|
||||
|
|
@ -101,18 +87,16 @@ export class RemoteUserResolveService {
|
|||
lastFetchedAt: new Date(),
|
||||
});
|
||||
|
||||
this.logger.info(`try resync: ${acctLower}`);
|
||||
const self = await this.resolveSelf(acctLower);
|
||||
|
||||
if (user.uri !== self.href) {
|
||||
// if uri mismatch, Fix (user@host <=> AP's Person id(RemoteUser.uri)) mapping.
|
||||
this.logger.info(`uri missmatch: ${acctLower}`);
|
||||
this.logger.info(`recovery missmatch uri for (username=${username}, host=${host}) from ${user.uri} to ${self.href}`);
|
||||
this.logger.warn(`Detected URI mismatch for ${acctLower}`);
|
||||
|
||||
// validate uri
|
||||
const uri = new URL(self.href);
|
||||
if (uri.hostname !== host) {
|
||||
throw new Error('Invalid uri');
|
||||
const uriHost = this.utilityService.extractDbHost(self.href);
|
||||
if (uriHost !== host) {
|
||||
throw new Error(`Failed to correct URI for ${acctLower}: new URI ${self.href} has different host from previous URI ${user.uri}`);
|
||||
}
|
||||
|
||||
await this.usersRepository.update({
|
||||
|
|
@ -121,37 +105,28 @@ export class RemoteUserResolveService {
|
|||
}, {
|
||||
uri: self.href,
|
||||
});
|
||||
} else {
|
||||
this.logger.info(`uri is fine: ${acctLower}`);
|
||||
}
|
||||
|
||||
this.logger.info(`Corrected URI for ${acctLower} from ${user.uri} to ${self.href}`);
|
||||
|
||||
await this.apPersonService.updatePerson(self.href);
|
||||
|
||||
this.logger.info(`return resynced remote user: ${acctLower}`);
|
||||
return await this.usersRepository.findOneBy({ uri: self.href }).then(u => {
|
||||
if (u == null) {
|
||||
throw new Error('user not found');
|
||||
} else {
|
||||
return u as MiLocalUser | MiRemoteUser;
|
||||
}
|
||||
});
|
||||
return await this.usersRepository.findOneByOrFail({ uri: self.href }) as MiLocalUser | MiRemoteUser;
|
||||
}
|
||||
|
||||
this.logger.info(`return existing remote user: ${acctLower}`);
|
||||
return user;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async resolveSelf(acctLower: string): Promise<ILink> {
|
||||
this.logger.info(`WebFinger for ${chalk.yellow(acctLower)}`);
|
||||
const finger = await this.webfingerService.webfinger(acctLower).catch(err => {
|
||||
this.logger.error(`Failed to WebFinger for ${chalk.yellow(acctLower)}: ${ err.statusCode ?? err.message }`);
|
||||
throw new Error(`Failed to WebFinger for ${acctLower}: ${ err.statusCode ?? err.message }`);
|
||||
this.logger.error(`Failed to WebFinger for ${chalk.yellow(acctLower)}: ${renderInlineError(err)}`);
|
||||
throw new Error(`Failed to WebFinger for ${acctLower}: error thrown`, { cause: err });
|
||||
});
|
||||
const self = finger.links.find(link => link.rel != null && link.rel.toLowerCase() === 'self');
|
||||
if (!self) {
|
||||
this.logger.error(`Failed to WebFinger for ${chalk.yellow(acctLower)}: self link not found`);
|
||||
throw new Error('self link not found');
|
||||
throw new Error(`Failed to WebFinger for ${acctLower}: self link not found`);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import type { Config } from '@/config.js';
|
|||
import { bindThis } from '@/decorators.js';
|
||||
import { MiUser } from '@/models/_.js';
|
||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import Logger from '@/logger.js';
|
||||
import type {
|
||||
AuthenticationResponseJSON,
|
||||
AuthenticatorTransportFuture,
|
||||
|
|
@ -28,6 +30,8 @@ import type {
|
|||
|
||||
@Injectable()
|
||||
export class WebAuthnService {
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(
|
||||
@Inject(DI.config)
|
||||
private config: Config,
|
||||
|
|
@ -40,7 +44,9 @@ export class WebAuthnService {
|
|||
|
||||
@Inject(DI.userSecurityKeysRepository)
|
||||
private userSecurityKeysRepository: UserSecurityKeysRepository,
|
||||
loggerService: LoggerService,
|
||||
) {
|
||||
this.logger = loggerService.getLogger('web-authn');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
|
|
@ -114,8 +120,8 @@ export class WebAuthnService {
|
|||
requireUserVerification: true,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw new IdentifiableError('5c1446f8-8ca7-4d31-9f39-656afe9c5d87', 'verification failed');
|
||||
this.logger.error(error as Error, 'Error authenticating webauthn');
|
||||
throw new IdentifiableError('5c1446f8-8ca7-4d31-9f39-656afe9c5d87', 'verification failed', true, error);
|
||||
}
|
||||
|
||||
const { verified } = verification;
|
||||
|
|
@ -221,7 +227,7 @@ export class WebAuthnService {
|
|||
requireUserVerification: true,
|
||||
});
|
||||
} catch (error) {
|
||||
throw new IdentifiableError('b18c89a7-5b5e-4cec-bb5b-0419f332d430', `verification failed: ${error}`);
|
||||
throw new IdentifiableError('b18c89a7-5b5e-4cec-bb5b-0419f332d430', `verification failed`, true, error);
|
||||
}
|
||||
|
||||
const { verified, authenticationInfo } = verification;
|
||||
|
|
@ -301,8 +307,8 @@ export class WebAuthnService {
|
|||
requireUserVerification: true,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw new IdentifiableError('b18c89a7-5b5e-4cec-bb5b-0419f332d430', 'verification failed');
|
||||
this.logger.error(error as Error, 'Error authenticating webauthn');
|
||||
throw new IdentifiableError('b18c89a7-5b5e-4cec-bb5b-0419f332d430', 'verification failed', true, error);
|
||||
}
|
||||
|
||||
const { verified, authenticationInfo } = verification;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { XMLParser } from 'fast-xml-parser';
|
|||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import type Logger from '@/logger.js';
|
||||
import { renderInlineError } from '@/misc/render-inline-error.js';
|
||||
import { RemoteLoggerService } from './RemoteLoggerService.js';
|
||||
|
||||
export type ILink = {
|
||||
|
|
@ -109,7 +110,7 @@ export class WebfingerService {
|
|||
const template = (hostMeta['XRD']['Link'] as Array<any>).filter(p => p['@_rel'] === 'lrdd')[0]['@_template'];
|
||||
return template.indexOf('{uri}') < 0 ? null : template;
|
||||
} catch (err) {
|
||||
this.logger.error(`error while request host-meta for ${url}: ${err}`);
|
||||
this.logger.error(`error while request host-meta for ${url}: ${renderInlineError(err)}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,18 +165,23 @@ export class ApDbResolverService implements OnApplicationShutdown {
|
|||
*/
|
||||
@bindThis
|
||||
public async refetchPublicKeyForApId(user: MiRemoteUser): Promise<MiUserPublickey | null> {
|
||||
this.apLoggerService.logger.debug('Re-fetching public key for user', { userId: user.id, uri: user.uri });
|
||||
this.apLoggerService.logger.debug(`Updating public key for user ${user.id} (${user.uri})`);
|
||||
|
||||
const oldKey = await this.apPersonService.findPublicKeyByUserId(user.id);
|
||||
await this.apPersonService.updatePerson(user.uri);
|
||||
const newKey = await this.apPersonService.findPublicKeyByUserId(user.id);
|
||||
|
||||
const key = await this.apPersonService.findPublicKeyByUserId(user.id);
|
||||
|
||||
if (key) {
|
||||
this.apLoggerService.logger.info('Re-fetched public key for user', { userId: user.id, uri: user.uri });
|
||||
if (newKey) {
|
||||
if (oldKey && newKey.keyPem === oldKey.keyPem) {
|
||||
this.apLoggerService.logger.debug(`Public key is up-to-date for user ${user.id} (${user.uri})`);
|
||||
} else {
|
||||
this.apLoggerService.logger.info(`Updated public key for user ${user.id} (${user.uri})`);
|
||||
}
|
||||
} else {
|
||||
this.apLoggerService.logger.warn('Failed to re-fetch key for user', { userId: user.id, uri: user.uri });
|
||||
this.apLoggerService.logger.warn(`Failed to update public key for user ${user.id} (${user.uri})`);
|
||||
}
|
||||
|
||||
return key;
|
||||
return newKey ?? oldKey;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class DeliverManager {
|
|||
) {
|
||||
// 型で弾いてはいるが一応ローカルユーザーかチェック
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
if (actor.host != null) throw new Error('actor.host must be null');
|
||||
if (actor.host != null) throw new Error(`deliver failed for ${actor.id}: host is not null`);
|
||||
|
||||
// パフォーマンス向上のためキューに突っ込むのはidのみに絞る
|
||||
this.actor = {
|
||||
|
|
@ -124,12 +124,13 @@ class DeliverManager {
|
|||
select: {
|
||||
followerSharedInbox: true,
|
||||
followerInbox: true,
|
||||
followerId: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (const following of followers) {
|
||||
const inbox = following.followerSharedInbox ?? following.followerInbox;
|
||||
if (inbox === null) throw new UnrecoverableError(`inbox is null: following ${following.id}`);
|
||||
if (inbox === null) throw new UnrecoverableError(`deliver failed for ${this.actor.id}: follower ${following.followerId} inbox is null`);
|
||||
inboxes.set(inbox, following.followerSharedInbox != null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import { AbuseReportService } from '@/core/AbuseReportService.js';
|
|||
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
|
||||
import { fromTuple } from '@/misc/from-tuple.js';
|
||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||
import { renderInlineError } from '@/misc/render-inline-error.js';
|
||||
import InstanceChart from '@/core/chart/charts/instance.js';
|
||||
import FederationChart from '@/core/chart/charts/federation.js';
|
||||
import { FetchInstanceMetadataService } from '@/core/FetchInstanceMetadataService.js';
|
||||
|
|
@ -121,13 +122,14 @@ export class ApInboxService {
|
|||
act.id = undefined;
|
||||
}
|
||||
|
||||
const id = getNullableApId(act) ?? `${getNullableApId(activity)}#${i}`;
|
||||
|
||||
try {
|
||||
const id = getNullableApId(act) ?? `${getNullableApId(activity)}#${i}`;
|
||||
const result = await this.performOneActivity(actor, act, resolver);
|
||||
results.push([id, result]);
|
||||
} catch (err) {
|
||||
if (err instanceof Error || typeof err === 'string') {
|
||||
this.logger.error(err);
|
||||
this.logger.error(`Unhandled error in activity ${id}:`, err);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
|
|
@ -147,7 +149,8 @@ export class ApInboxService {
|
|||
if (actor.lastFetchedAt == null || Date.now() - actor.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) {
|
||||
setImmediate(() => {
|
||||
// 同一ユーザーの情報を再度処理するので、使用済みのresolverを再利用してはいけない
|
||||
this.apPersonService.updatePerson(actor.uri);
|
||||
this.apPersonService.updatePerson(actor.uri)
|
||||
.catch(err => this.logger.error(`Failed to update person: ${renderInlineError(err)}`));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -253,7 +256,7 @@ export class ApInboxService {
|
|||
resolver ??= this.apResolverService.createResolver();
|
||||
|
||||
const object = await resolver.resolve(activity.object).catch(err => {
|
||||
this.logger.error(`Resolution failed: ${err}`);
|
||||
this.logger.error(`Resolution failed: ${renderInlineError(err)}`);
|
||||
throw err;
|
||||
});
|
||||
|
||||
|
|
@ -326,7 +329,7 @@ export class ApInboxService {
|
|||
if (targetUri.startsWith('bear:')) return 'skip: bearcaps url not supported.';
|
||||
|
||||
const target = await resolver.secureResolve(activityObject, uri).catch(e => {
|
||||
this.logger.error(`Resolution failed: ${e}`);
|
||||
this.logger.error(`Resolution failed: ${renderInlineError(e)}`);
|
||||
throw e;
|
||||
});
|
||||
|
||||
|
|
@ -357,22 +360,10 @@ export class ApInboxService {
|
|||
}
|
||||
|
||||
// Announce対象をresolve
|
||||
let renote;
|
||||
try {
|
||||
// The target ID is verified by secureResolve, so we know it shares host authority with the actor who sent it.
|
||||
// This means we can pass that ID to resolveNote and avoid an extra fetch, which will fail if the note is private.
|
||||
renote = await this.apNoteService.resolveNote(target, { resolver, sentFrom: getApId(target) });
|
||||
if (renote == null) return 'announce target is null';
|
||||
} catch (err) {
|
||||
// 対象が4xxならスキップ
|
||||
if (err instanceof StatusError) {
|
||||
if (!err.isRetryable) {
|
||||
return `skip: ignored announce target ${target.id} - ${err.statusCode}`;
|
||||
}
|
||||
return `Error in announce target ${target.id} - ${err.statusCode}`;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
// The target ID is verified by secureResolve, so we know it shares host authority with the actor who sent it.
|
||||
// This means we can pass that ID to resolveNote and avoid an extra fetch, which will fail if the note is private.
|
||||
const renote = await this.apNoteService.resolveNote(target, { resolver, sentFrom: getApId(target) });
|
||||
if (renote == null) return 'announce target is null';
|
||||
|
||||
if (!await this.noteEntityService.isVisibleForMe(renote, actor.id)) {
|
||||
return 'skip: invalid actor for this activity';
|
||||
|
|
@ -454,9 +445,11 @@ export class ApInboxService {
|
|||
setImmediate(() => {
|
||||
// Don't re-use the resolver, or it may throw recursion errors.
|
||||
// Instead, create a new resolver with an appropriately-reduced recursion limit.
|
||||
this.apPersonService.updatePerson(actor.uri, this.apResolverService.createResolver({
|
||||
const subResolver = this.apResolverService.createResolver({
|
||||
recursionLimit: resolver.getRecursionLimit() - resolver.getHistory().length,
|
||||
}));
|
||||
});
|
||||
this.apPersonService.updatePerson(actor.uri, subResolver)
|
||||
.catch(err => this.logger.error(`Failed to update person: ${renderInlineError(err)}`));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -511,7 +504,7 @@ export class ApInboxService {
|
|||
resolver ??= this.apResolverService.createResolver();
|
||||
|
||||
const object = await resolver.resolve(activityObject).catch(e => {
|
||||
this.logger.error(`Resolution failed: ${e}`);
|
||||
this.logger.error(`Resolution failed: ${renderInlineError(e)}`);
|
||||
throw e;
|
||||
});
|
||||
|
||||
|
|
@ -548,12 +541,6 @@ export class ApInboxService {
|
|||
|
||||
await this.apNoteService.createNote(note, actor, resolver, silent);
|
||||
return 'ok';
|
||||
} catch (err) {
|
||||
if (err instanceof StatusError && !err.isRetryable) {
|
||||
return `skip: ${err.statusCode}`;
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
|
|
@ -686,7 +673,7 @@ export class ApInboxService {
|
|||
resolver ??= this.apResolverService.createResolver();
|
||||
|
||||
const object = await resolver.resolve(activity.object).catch(e => {
|
||||
this.logger.error(`Resolution failed: ${e}`);
|
||||
this.logger.error(`Resolution failed: ${renderInlineError(e)}`);
|
||||
throw e;
|
||||
});
|
||||
|
||||
|
|
@ -758,7 +745,7 @@ export class ApInboxService {
|
|||
resolver ??= this.apResolverService.createResolver();
|
||||
|
||||
const object = await resolver.resolve(activity.object).catch(e => {
|
||||
this.logger.error(`Resolution failed: ${e}`);
|
||||
this.logger.error(`Resolution failed: ${renderInlineError(e)}`);
|
||||
throw e;
|
||||
});
|
||||
|
||||
|
|
@ -890,7 +877,7 @@ export class ApInboxService {
|
|||
resolver ??= this.apResolverService.createResolver();
|
||||
|
||||
const object = await resolver.resolve(activity.object).catch(e => {
|
||||
this.logger.error(`Resolution failed: ${e}`);
|
||||
this.logger.error(`Resolution failed: ${renderInlineError(e)}`);
|
||||
throw e;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ export class Resolver {
|
|||
if (isCollectionOrOrderedCollection(collection)) {
|
||||
return collection;
|
||||
} else {
|
||||
throw new IdentifiableError('f100eccf-f347-43fb-9b45-96a0831fb635', `unrecognized collection type: ${collection.type}`);
|
||||
throw new IdentifiableError('f100eccf-f347-43fb-9b45-96a0831fb635', `collection ${getApId(value)} has unsupported type: ${collection.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ export class Resolver {
|
|||
}
|
||||
|
||||
// This ensures the input has a string ID, protecting against type confusion and rejecting anonymous objects.
|
||||
const id = getApId(value);
|
||||
const id = getApId(value, sentFromUri);
|
||||
|
||||
// Check if we can use the provided object as-is.
|
||||
// Our security requires that the object ID matches the host authority that sent it, otherwise it can't be trusted.
|
||||
|
|
@ -276,15 +276,15 @@ export class Resolver {
|
|||
// URLs with fragment parts cannot be resolved correctly because
|
||||
// the fragment part does not get transmitted over HTTP(S).
|
||||
// Avoid strange behaviour by not trying to resolve these at all.
|
||||
throw new IdentifiableError('b94fd5b1-0e3b-4678-9df2-dad4cd515ab2', `cannot resolve URL with fragment: ${value}`);
|
||||
throw new IdentifiableError('b94fd5b1-0e3b-4678-9df2-dad4cd515ab2', `failed to resolve ${value}: URL contains fragment`);
|
||||
}
|
||||
|
||||
if (this.history.has(value)) {
|
||||
throw new IdentifiableError('0dc86cf6-7cd6-4e56-b1e6-5903d62d7ea5', `cannot resolve already resolved URL: ${value}`);
|
||||
throw new IdentifiableError('0dc86cf6-7cd6-4e56-b1e6-5903d62d7ea5', `failed to resolve ${value}: recursive resolution blocked`);
|
||||
}
|
||||
|
||||
if (this.history.size > this.recursionLimit) {
|
||||
throw new IdentifiableError('d592da9f-822f-4d91-83d7-4ceefabcf3d2', `hit recursion limit: ${value}`);
|
||||
throw new IdentifiableError('d592da9f-822f-4d91-83d7-4ceefabcf3d2', `failed to resolve ${value}: hit recursion limit`);
|
||||
}
|
||||
|
||||
this.history.add(value);
|
||||
|
|
@ -294,7 +294,7 @@ export class Resolver {
|
|||
}
|
||||
|
||||
if (!this.utilityService.isFederationAllowedHost(host)) {
|
||||
throw new IdentifiableError('09d79f9e-64f1-4316-9cfa-e75c4d091574', `cannot fetch AP object ${value}: blocked instance ${host}`);
|
||||
throw new IdentifiableError('09d79f9e-64f1-4316-9cfa-e75c4d091574', `failed to resolve ${value}: instance ${host} is blocked`);
|
||||
}
|
||||
|
||||
if (this.config.signToActivityPubGet && !this.user) {
|
||||
|
|
@ -324,12 +324,12 @@ export class Resolver {
|
|||
!(object['@context'] as unknown[]).includes('https://www.w3.org/ns/activitystreams') :
|
||||
object['@context'] !== 'https://www.w3.org/ns/activitystreams'
|
||||
) {
|
||||
throw new IdentifiableError('72180409-793c-4973-868e-5a118eb5519b', `invalid AP object ${value}: does not have ActivityStreams context`);
|
||||
throw new IdentifiableError('72180409-793c-4973-868e-5a118eb5519b', `failed to resolve ${value}: response does not have ActivityStreams context`);
|
||||
}
|
||||
|
||||
// The object ID is already validated to match the final URL's authority by signedGet / getActivityJson.
|
||||
// We only need to validate that it also matches the original URL's authority, in case of redirects.
|
||||
const objectId = getApId(object);
|
||||
const objectId = getApId(object, value);
|
||||
|
||||
// We allow some limited cross-domain redirects, which means the host may have changed during fetch.
|
||||
// Additional checks are needed to validate the scope of cross-domain redirects.
|
||||
|
|
@ -340,7 +340,7 @@ export class Resolver {
|
|||
|
||||
// Check if the redirect bounce from [allowed domain] to [blocked domain].
|
||||
if (!this.utilityService.isFederationAllowedHost(finalHost)) {
|
||||
throw new IdentifiableError('0a72bf24-2d9b-4f1d-886b-15aaa31adeda', `cannot fetch AP object ${value}: redirected to blocked instance ${finalHost}`);
|
||||
throw new IdentifiableError('0a72bf24-2d9b-4f1d-886b-15aaa31adeda', `failed to resolve ${value}: redirected to blocked instance ${finalHost}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -351,7 +351,7 @@ export class Resolver {
|
|||
@bindThis
|
||||
private resolveLocal(url: string): Promise<IObjectWithId> {
|
||||
const parsed = this.apDbResolverService.parseUri(url);
|
||||
if (!parsed.local) throw new IdentifiableError('02b40cd0-fa92-4b0c-acc9-fb2ada952ab8', `resolveLocal - not a local URL: ${url}`);
|
||||
if (!parsed.local) throw new IdentifiableError('02b40cd0-fa92-4b0c-acc9-fb2ada952ab8', `failed to resolve local ${url}: not a local URL`);
|
||||
|
||||
switch (parsed.type) {
|
||||
case 'notes':
|
||||
|
|
@ -385,7 +385,7 @@ export class Resolver {
|
|||
case 'follows':
|
||||
return this.followRequestsRepository.findOneBy({ id: parsed.id })
|
||||
.then(async followRequest => {
|
||||
if (followRequest == null) throw new IdentifiableError('a9d946e5-d276-47f8-95fb-f04230289bb0', `resolveLocal - invalid follow request ID ${parsed.id}: ${url}`);
|
||||
if (followRequest == null) throw new IdentifiableError('a9d946e5-d276-47f8-95fb-f04230289bb0', `failed to resolve local ${url}: invalid follow request ID`);
|
||||
const [follower, followee] = await Promise.all([
|
||||
this.usersRepository.findOneBy({
|
||||
id: followRequest.followerId,
|
||||
|
|
@ -397,12 +397,12 @@ export class Resolver {
|
|||
}),
|
||||
]);
|
||||
if (follower == null || followee == null) {
|
||||
throw new IdentifiableError('06ae3170-1796-4d93-a697-2611ea6d83b6', `resolveLocal - follower or followee does not exist: ${url}`);
|
||||
throw new IdentifiableError('06ae3170-1796-4d93-a697-2611ea6d83b6', `failed to resolve local ${url}: follower or followee does not exist`);
|
||||
}
|
||||
return this.apRendererService.addContext(this.apRendererService.renderFollow(follower as MiLocalUser | MiRemoteUser, followee as MiLocalUser | MiRemoteUser, url));
|
||||
});
|
||||
default:
|
||||
throw new IdentifiableError('7a5d2fc0-94bc-4db6-b8b8-1bf24a2e23d0', `resolveLocal: type ${parsed.type} unhandled: ${url}`);
|
||||
throw new IdentifiableError('7a5d2fc0-94bc-4db6-b8b8-1bf24a2e23d0', `failed to resolve local ${url}: unsupported type ${parsed.type}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export class ApUtilityService {
|
|||
public assertIdMatchesUrlAuthority(object: IObject, url: string): void {
|
||||
// This throws if the ID is missing or invalid, but that's ok.
|
||||
// Anonymous objects are impossible to verify, so we don't allow fetching them.
|
||||
const id = getApId(object);
|
||||
const id = getApId(object, url);
|
||||
|
||||
// Make sure the object ID matches the final URL (which is where it actually exists).
|
||||
// The caller (ApResolverService) will verify the ID against the original / entry URL, which ensures that all three match.
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { Injectable } from '@nestjs/common';
|
|||
import { UnrecoverableError } from 'bullmq';
|
||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { StatusError } from '@/misc/status-error.js';
|
||||
import { CONTEXT, PRELOADED_CONTEXTS } from './misc/contexts.js';
|
||||
import { validateContentTypeSetAsJsonLD } from './misc/validator.js';
|
||||
import type { JsonLdDocument } from 'jsonld';
|
||||
|
|
@ -149,7 +150,7 @@ class JsonLd {
|
|||
},
|
||||
).then(res => {
|
||||
if (!res.ok) {
|
||||
throw new Error(`JSON-LD fetch failed with ${res.status} ${res.statusText}: ${url}`);
|
||||
throw new StatusError(`failed to fetch JSON-LD from ${url}`, res.status, res.statusText);
|
||||
} else {
|
||||
return res.json();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,14 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||
import type { Response } from 'node-fetch';
|
||||
|
||||
// TODO throw identifiable or unrecoverable errors
|
||||
|
||||
export function validateContentTypeSetAsActivityPub(response: Response): void {
|
||||
const contentType = (response.headers.get('content-type') ?? '').toLowerCase();
|
||||
|
||||
if (contentType === '') {
|
||||
throw new Error(`invalid content type of AP response - no content-type header: ${response.url}`);
|
||||
throw new IdentifiableError('d09dc850-b76c-4f45-875a-7389339d78b8', `invalid AP response from ${response.url}: no content-type header`, true);
|
||||
}
|
||||
if (
|
||||
contentType.startsWith('application/activity+json') ||
|
||||
|
|
@ -19,7 +18,7 @@ export function validateContentTypeSetAsActivityPub(response: Response): void {
|
|||
) {
|
||||
return;
|
||||
}
|
||||
throw new Error(`invalid content type of AP response - content type is not application/activity+json or application/ld+json: ${response.url}`);
|
||||
throw new IdentifiableError('dc110060-a5f2-461d-808b-39c62702ca64', `invalid AP response from ${response.url}: content type "${contentType}" is not application/activity+json or application/ld+json`);
|
||||
}
|
||||
|
||||
const plusJsonSuffixRegex = /^\s*(application|text)\/[a-zA-Z0-9\.\-\+]+\+json\s*(;|$)/;
|
||||
|
|
@ -28,7 +27,7 @@ export function validateContentTypeSetAsJsonLD(response: Response): void {
|
|||
const contentType = (response.headers.get('content-type') ?? '').toLowerCase();
|
||||
|
||||
if (contentType === '') {
|
||||
throw new Error(`invalid content type of JSON LD - no content-type header: ${response.url}`);
|
||||
throw new IdentifiableError('45793ab7-7648-4886-b503-429f8a0d0f73', `invalid AP response from ${response.url}: no content-type header`, true);
|
||||
}
|
||||
if (
|
||||
contentType.startsWith('application/ld+json') ||
|
||||
|
|
@ -37,5 +36,5 @@ export function validateContentTypeSetAsJsonLD(response: Response): void {
|
|||
) {
|
||||
return;
|
||||
}
|
||||
throw new Error(`invalid content type of JSON LD - content type is not application/ld+json or application/json: ${response.url}`);
|
||||
throw new IdentifiableError('4bf8f36b-4d33-4ac9-ad76-63fa11f354e9', `invalid AP response from ${response.url}: content type "${contentType}" is not application/ld+json or application/json`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import type { Config } from '@/config.js';
|
|||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||
import { ApResolverService } from '../ApResolverService.js';
|
||||
import { ApLoggerService } from '../ApLoggerService.js';
|
||||
import { isDocument, type IObject } from '../type.js';
|
||||
import { getNullableApId, isDocument, type IObject } from '../type.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApImageService {
|
||||
|
|
@ -48,7 +48,7 @@ export class ApImageService {
|
|||
public async createImage(actor: MiRemoteUser, value: string | IObject): Promise<MiDriveFile | null> {
|
||||
// 投稿者が凍結されていたらスキップ
|
||||
if (actor.isSuspended) {
|
||||
throw new IdentifiableError('85ab9bd7-3a41-4530-959d-f07073900109', `actor has been suspended: ${actor.uri}`);
|
||||
throw new IdentifiableError('85ab9bd7-3a41-4530-959d-f07073900109', `failed to create image ${getNullableApId(value)}: actor ${actor.id} has been suspended`);
|
||||
}
|
||||
|
||||
const image = await this.apResolverService.createResolver().resolve(value);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import { bindThis } from '@/decorators.js';
|
|||
import { checkHttps } from '@/misc/check-https.js';
|
||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||
import { isRetryableError } from '@/misc/is-retryable-error.js';
|
||||
import { renderInlineError } from '@/misc/render-inline-error.js';
|
||||
import { getOneApId, getApId, validPost, isEmoji, getApType, isApObject, isDocument, IApDocument } from '../type.js';
|
||||
import { ApLoggerService } from '../ApLoggerService.js';
|
||||
import { ApMfmService } from '../ApMfmService.js';
|
||||
|
|
@ -100,29 +101,29 @@ export class ApNoteService {
|
|||
const apType = getApType(object);
|
||||
|
||||
if (apType == null || !validPost.includes(apType)) {
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', `invalid Note: invalid object type ${apType ?? 'undefined'}`);
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', `invalid Note from ${uri}: invalid object type ${apType ?? 'undefined'}`);
|
||||
}
|
||||
|
||||
if (object.id && this.utilityService.extractDbHost(object.id) !== expectHost) {
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', `invalid Note: id has different host. expected: ${expectHost}, actual: ${this.utilityService.extractDbHost(object.id)}`);
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', `invalid Note from ${uri}: id has different host. expected: ${expectHost}, actual: ${this.utilityService.extractDbHost(object.id)}`);
|
||||
}
|
||||
|
||||
const actualHost = object.attributedTo && this.utilityService.extractDbHost(getOneApId(object.attributedTo));
|
||||
if (object.attributedTo && actualHost !== expectHost) {
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', `invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${actualHost}`);
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', `invalid Note from ${uri}: attributedTo has different host. expected: ${expectHost}, actual: ${actualHost}`);
|
||||
}
|
||||
|
||||
if (object.published && !this.idService.isSafeT(new Date(object.published).valueOf())) {
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', 'invalid Note: published timestamp is malformed');
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', 'invalid Note from ${uri}: published timestamp is malformed');
|
||||
}
|
||||
|
||||
if (actor) {
|
||||
const attribution = (object.attributedTo) ? getOneApId(object.attributedTo) : actor.uri;
|
||||
if (attribution !== actor.uri) {
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', `invalid Note: attribution does not match the actor that send it. attribution: ${attribution}, actor: ${actor.uri}`);
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', `invalid Note from ${uri}: attribution does not match the actor that send it. attribution: ${attribution}, actor: ${actor.uri}`);
|
||||
}
|
||||
if (user && attribution !== user.uri) {
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', `invalid Note: updated attribution does not match original attribution. updated attribution: ${user.uri}, original attribution: ${attribution}`);
|
||||
return new IdentifiableError('d450b8a9-48e4-4dab-ae36-f4db763fda7c', `invalid Note from ${uri}: updated attribution does not match original attribution. updated attribution: ${user.uri}, original attribution: ${attribution}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -161,7 +162,7 @@ export class ApNoteService {
|
|||
const entryUri = getApId(value);
|
||||
const err = this.validateNote(object, entryUri, actor);
|
||||
if (err) {
|
||||
this.logger.error(err.message, {
|
||||
this.logger.error(`Error creating note: ${renderInlineError(err)}`, {
|
||||
resolver: { history: resolver.getHistory() },
|
||||
value,
|
||||
object,
|
||||
|
|
@ -174,11 +175,11 @@ export class ApNoteService {
|
|||
this.logger.debug(`Note fetched: ${JSON.stringify(note, null, 2)}`);
|
||||
|
||||
if (note.id == null) {
|
||||
throw new UnrecoverableError(`Refusing to create note without id: ${entryUri}`);
|
||||
throw new UnrecoverableError(`failed to create note ${entryUri}: missing ID`);
|
||||
}
|
||||
|
||||
if (!checkHttps(note.id)) {
|
||||
throw new UnrecoverableError(`unexpected schema of note.id ${note.id} in ${entryUri}`);
|
||||
throw new UnrecoverableError(`failed to create note ${entryUri}: unexpected schema`);
|
||||
}
|
||||
|
||||
const url = this.apUtilityService.findBestObjectUrl(note);
|
||||
|
|
@ -187,7 +188,7 @@ export class ApNoteService {
|
|||
|
||||
// 投稿者をフェッチ
|
||||
if (note.attributedTo == null) {
|
||||
throw new UnrecoverableError(`invalid note.attributedTo ${note.attributedTo} in ${entryUri}`);
|
||||
throw new UnrecoverableError(`failed to create note: ${entryUri}: missing attributedTo`);
|
||||
}
|
||||
|
||||
const uri = getOneApId(note.attributedTo);
|
||||
|
|
@ -196,7 +197,7 @@ export class ApNoteService {
|
|||
// eslint-disable-next-line no-param-reassign
|
||||
actor ??= await this.apPersonService.fetchPerson(uri) as MiRemoteUser | undefined;
|
||||
if (actor && actor.isSuspended) {
|
||||
throw new IdentifiableError('85ab9bd7-3a41-4530-959d-f07073900109', `actor ${uri} has been suspended: ${entryUri}`);
|
||||
throw new IdentifiableError('85ab9bd7-3a41-4530-959d-f07073900109', `failed to create note ${entryUri}: actor ${uri} has been suspended`);
|
||||
}
|
||||
|
||||
const apMentions = await this.apMentionService.extractApMentions(note.tag, resolver);
|
||||
|
|
@ -223,7 +224,7 @@ export class ApNoteService {
|
|||
*/
|
||||
const hasProhibitedWords = this.noteCreateService.checkProhibitedWordsContain({ cw, text, pollChoices: poll?.choices });
|
||||
if (hasProhibitedWords) {
|
||||
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140af99', `Note contains prohibited words: ${entryUri}`);
|
||||
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140af99', `failed to create note ${entryUri}: contains prohibited words`);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
|
|
@ -232,7 +233,7 @@ export class ApNoteService {
|
|||
|
||||
// 解決した投稿者が凍結されていたらスキップ
|
||||
if (actor.isSuspended) {
|
||||
throw new IdentifiableError('85ab9bd7-3a41-4530-959d-f07073900109', `actor has been suspended: ${entryUri}`);
|
||||
throw new IdentifiableError('85ab9bd7-3a41-4530-959d-f07073900109', `failed to create note ${entryUri}: actor ${actor.id} has been suspended`);
|
||||
}
|
||||
|
||||
const noteAudience = await this.apAudienceService.parseAudience(actor, note.to, note.cc, resolver);
|
||||
|
|
@ -269,15 +270,15 @@ export class ApNoteService {
|
|||
? await this.resolveNote(note.inReplyTo, { resolver })
|
||||
.then(x => {
|
||||
if (x == null) {
|
||||
this.logger.warn('Specified inReplyTo, but not found');
|
||||
throw new Error(`could not fetch inReplyTo ${note.inReplyTo} for note ${entryUri}`);
|
||||
this.logger.warn(`Specified inReplyTo "${note.inReplyTo}", but not found`);
|
||||
throw new IdentifiableError('1ebf0a96-2769-4973-a6c2-3dcbad409dff', `failed to create note ${entryUri}: could not fetch inReplyTo ${note.inReplyTo}`, true);
|
||||
}
|
||||
|
||||
return x;
|
||||
})
|
||||
.catch(async err => {
|
||||
this.logger.warn(`error ${err.statusCode ?? err} fetching inReplyTo ${note.inReplyTo} for note ${entryUri}`);
|
||||
throw err;
|
||||
this.logger.warn(`error ${renderInlineError(err)} fetching inReplyTo ${note.inReplyTo} for note ${entryUri}`);
|
||||
throw new IdentifiableError('1ebf0a96-2769-4973-a6c2-3dcbad409dff', `failed to create note ${entryUri}: could not fetch inReplyTo ${note.inReplyTo}`, true, err);
|
||||
})
|
||||
: null;
|
||||
|
||||
|
|
@ -348,7 +349,7 @@ export class ApNoteService {
|
|||
this.logger.info('The note is already inserted while creating itself, reading again');
|
||||
const duplicate = await this.fetchNote(value);
|
||||
if (!duplicate) {
|
||||
throw new Error(`The note creation failed with duplication error even when there is no duplication: ${entryUri}`);
|
||||
throw new IdentifiableError('39c328e1-e829-458b-bfc9-65dcd513d1f8', `failed to create note ${entryUri}: the note creation failed with duplication error even when there is no duplication. This is likely a bug.`);
|
||||
}
|
||||
return duplicate;
|
||||
}
|
||||
|
|
@ -362,45 +363,39 @@ export class ApNoteService {
|
|||
const noteUri = getApId(value);
|
||||
|
||||
// URIがこのサーバーを指しているならスキップ
|
||||
if (noteUri.startsWith(this.config.url + '/')) throw new UnrecoverableError(`uri points local: ${noteUri}`);
|
||||
if (this.utilityService.isUriLocal(noteUri)) {
|
||||
throw new UnrecoverableError(`failed to update note ${noteUri}: uri is local`);
|
||||
}
|
||||
|
||||
//#region このサーバーに既に登録されているか
|
||||
const updatedNote = await this.notesRepository.findOneBy({ uri: noteUri });
|
||||
if (updatedNote == null) throw new Error(`Note is not registered (no note): ${noteUri}`);
|
||||
if (updatedNote == null) throw new UnrecoverableError(`failed to update note ${noteUri}: note does not exist`);
|
||||
|
||||
const user = await this.usersRepository.findOneBy({ id: updatedNote.userId }) as MiRemoteUser | null;
|
||||
if (user == null) throw new Error(`Note is not registered (no user): ${noteUri}`);
|
||||
if (user == null) throw new UnrecoverableError(`failed to update note ${noteUri}: user does not exist`);
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
if (resolver == null) resolver = this.apResolverService.createResolver();
|
||||
resolver ??= this.apResolverService.createResolver();
|
||||
|
||||
const object = await resolver.resolve(value);
|
||||
|
||||
const entryUri = getApId(value);
|
||||
const err = this.validateNote(object, entryUri, actor, user);
|
||||
if (err) {
|
||||
this.logger.error(err.message, {
|
||||
resolver: { history: resolver.getHistory() },
|
||||
value,
|
||||
object,
|
||||
});
|
||||
this.logger.error(`Failed to update note ${noteUri}: ${renderInlineError(err)}`);
|
||||
throw err;
|
||||
}
|
||||
|
||||
// `validateNote` checks that the actor and user are one and the same
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
actor ??= user;
|
||||
|
||||
const note = object as IPost;
|
||||
|
||||
this.logger.debug(`Note fetched: ${JSON.stringify(note, null, 2)}`);
|
||||
|
||||
if (note.id == null) {
|
||||
throw new UnrecoverableError(`Refusing to update note without id: ${noteUri}`);
|
||||
throw new UnrecoverableError(`failed to update note ${entryUri}: missing ID`);
|
||||
}
|
||||
|
||||
if (!checkHttps(note.id)) {
|
||||
throw new UnrecoverableError(`unexpected schema of note.id ${note.id} in ${noteUri}`);
|
||||
throw new UnrecoverableError(`failed to update note ${entryUri}: unexpected schema`);
|
||||
}
|
||||
|
||||
const url = this.apUtilityService.findBestObjectUrl(note);
|
||||
|
|
@ -408,7 +403,7 @@ export class ApNoteService {
|
|||
this.logger.info(`Creating the Note: ${note.id}`);
|
||||
|
||||
if (actor.isSuspended) {
|
||||
throw new IdentifiableError('85ab9bd7-3a41-4530-959d-f07073900109', `actor ${actor.id} has been suspended: ${noteUri}`);
|
||||
throw new IdentifiableError('85ab9bd7-3a41-4530-959d-f07073900109', `failed to update note ${entryUri}: actor ${actor.id} has been suspended`);
|
||||
}
|
||||
|
||||
const apMentions = await this.apMentionService.extractApMentions(note.tag, resolver);
|
||||
|
|
@ -435,7 +430,7 @@ export class ApNoteService {
|
|||
*/
|
||||
const hasProhibitedWords = this.noteCreateService.checkProhibitedWordsContain({ cw, text, pollChoices: poll?.choices });
|
||||
if (hasProhibitedWords) {
|
||||
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140af99', `Note contains prohibited words: ${noteUri}`);
|
||||
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140af99', `failed to update note ${noteUri}: contains prohibited words`);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
|
|
@ -473,15 +468,15 @@ export class ApNoteService {
|
|||
? await this.resolveNote(note.inReplyTo, { resolver })
|
||||
.then(x => {
|
||||
if (x == null) {
|
||||
this.logger.warn('Specified inReplyTo, but not found');
|
||||
throw new Error(`could not fetch inReplyTo ${note.inReplyTo} for note ${entryUri}`);
|
||||
this.logger.warn(`Specified inReplyTo "${note.inReplyTo}", but not found`);
|
||||
throw new IdentifiableError('1ebf0a96-2769-4973-a6c2-3dcbad409dff', `failed to update note ${entryUri}: could not fetch inReplyTo ${note.inReplyTo}`, true);
|
||||
}
|
||||
|
||||
return x;
|
||||
})
|
||||
.catch(async err => {
|
||||
this.logger.warn(`error ${err.statusCode ?? err} fetching inReplyTo ${note.inReplyTo} for note ${entryUri}`);
|
||||
throw err;
|
||||
this.logger.warn(`error ${renderInlineError(err)} fetching inReplyTo ${note.inReplyTo} for note ${entryUri}`);
|
||||
throw new IdentifiableError('1ebf0a96-2769-4973-a6c2-3dcbad409dff', `failed to update note ${entryUri}: could not fetch inReplyTo ${note.inReplyTo}`, true, err);
|
||||
})
|
||||
: null;
|
||||
|
||||
|
|
@ -549,7 +544,7 @@ export class ApNoteService {
|
|||
this.logger.info('The note is already inserted while creating itself, reading again');
|
||||
const duplicate = await this.fetchNote(value);
|
||||
if (!duplicate) {
|
||||
throw new Error(`The note creation failed with duplication error even when there is no duplication: ${noteUri}`);
|
||||
throw new IdentifiableError('39c328e1-e829-458b-bfc9-65dcd513d1f8', `failed to update note ${entryUri}: the note update failed with duplication error even when there is no duplication. This is likely a bug.`);
|
||||
}
|
||||
return duplicate;
|
||||
}
|
||||
|
|
@ -566,8 +561,7 @@ export class ApNoteService {
|
|||
const uri = getApId(value);
|
||||
|
||||
if (!this.utilityService.isFederationAllowedUri(uri)) {
|
||||
// TODO convert to identifiable error
|
||||
throw new StatusError(`blocked host: ${uri}`, 451, 'blocked host');
|
||||
throw new IdentifiableError('04620a7e-044e-45ce-b72c-10e1bdc22e69', `failed to resolve note ${uri}: host is blocked`);
|
||||
}
|
||||
|
||||
//#region このサーバーに既に登録されていたらそれを返す
|
||||
|
|
@ -577,8 +571,7 @@ export class ApNoteService {
|
|||
|
||||
// Bail if local URI doesn't exist
|
||||
if (this.utilityService.isUriLocal(uri)) {
|
||||
// TODO convert to identifiable error
|
||||
throw new StatusError(`cannot resolve local note: ${uri}`, 400, 'cannot resolve local note');
|
||||
throw new IdentifiableError('cbac7358-23f2-4c70-833e-cffb4bf77913', `failed to resolve note ${uri}: URL is local and does not exist`);
|
||||
}
|
||||
|
||||
const unlock = await this.appLockService.getApLock(uri);
|
||||
|
|
@ -685,18 +678,13 @@ export class ApNoteService {
|
|||
const quote = await this.resolveNote(uri, { resolver });
|
||||
|
||||
if (quote == null) {
|
||||
this.logger.warn(`Failed to resolve quote "${uri}" for note "${entryUri}": request error`);
|
||||
this.logger.warn(`Failed to resolve quote "${uri}" for note "${entryUri}": fetch failed`);
|
||||
return false;
|
||||
}
|
||||
|
||||
return quote;
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
this.logger.warn(`Failed to resolve quote "${uri}" for note "${entryUri}":`, e);
|
||||
} else {
|
||||
this.logger.warn(`Failed to resolve quote "${uri}" for note "${entryUri}": ${e}`);
|
||||
}
|
||||
|
||||
this.logger.warn(`Failed to resolve quote "${uri}" for note "${entryUri}": ${renderInlineError(e)}`);
|
||||
return isRetryableError(e);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
|
|||
import promiseLimit from 'promise-limit';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { ModuleRef } from '@nestjs/core';
|
||||
import { AbortError } from 'node-fetch';
|
||||
import { UnrecoverableError } from 'bullmq';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { FollowingsRepository, InstancesRepository, MiMeta, UserProfilesRepository, UserPublickeysRepository, UsersRepository } from '@/models/_.js';
|
||||
|
|
@ -44,6 +43,8 @@ import { AppLockService } from '@/core/AppLockService.js';
|
|||
import { MemoryKVCache } from '@/misc/cache.js';
|
||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { verifyFieldLinks } from '@/misc/verify-field-link.js';
|
||||
import { isRetryableError } from '@/misc/is-retryable-error.js';
|
||||
import { renderInlineError } from '@/misc/render-inline-error.js';
|
||||
import { getApId, getApType, isActor, isCollection, isCollectionOrOrderedCollection, isPropertyValue } from '../type.js';
|
||||
import { extractApHashtags } from './tag.js';
|
||||
import type { OnModuleInit } from '@nestjs/common';
|
||||
|
|
@ -54,6 +55,7 @@ import type { ApLoggerService } from '../ApLoggerService.js';
|
|||
|
||||
import type { ApImageService } from './ApImageService.js';
|
||||
import type { IActor, ICollection, IObject, IOrderedCollection } from '../type.js';
|
||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||
|
||||
const nameLength = 128;
|
||||
const summaryLength = 2048;
|
||||
|
|
@ -157,21 +159,21 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
const expectHost = this.utilityService.punyHostPSLDomain(uri);
|
||||
|
||||
if (!isActor(x)) {
|
||||
throw new UnrecoverableError(`invalid Actor type '${x.type}' in ${uri}`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: unknown type '${x.type}'`);
|
||||
}
|
||||
|
||||
if (!(typeof x.id === 'string' && x.id.length > 0)) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong id type`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong id type`);
|
||||
}
|
||||
|
||||
if (!(typeof x.inbox === 'string' && x.inbox.length > 0)) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong inbox type`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong inbox type`);
|
||||
}
|
||||
|
||||
this.apUtilityService.assertApUrl(x.inbox);
|
||||
const inboxHost = this.utilityService.punyHostPSLDomain(x.inbox);
|
||||
if (inboxHost !== expectHost) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong inbox ${inboxHost}`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong inbox host ${inboxHost}`);
|
||||
}
|
||||
|
||||
const sharedInboxObject = x.sharedInbox ?? (x.endpoints ? x.endpoints.sharedInbox : undefined);
|
||||
|
|
@ -179,7 +181,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
const sharedInbox = getApId(sharedInboxObject);
|
||||
this.apUtilityService.assertApUrl(sharedInbox);
|
||||
if (!(typeof sharedInbox === 'string' && sharedInbox.length > 0 && this.utilityService.punyHostPSLDomain(sharedInbox) === expectHost)) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong shared inbox ${sharedInbox}`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong shared inbox ${sharedInbox}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +192,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
if (typeof collectionUri === 'string' && collectionUri.length > 0) {
|
||||
this.apUtilityService.assertApUrl(collectionUri);
|
||||
if (this.utilityService.punyHostPSLDomain(collectionUri) !== expectHost) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong ${collection} ${collectionUri}`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong ${collection} host ${collectionUri}`);
|
||||
}
|
||||
} else if (collectionUri != null) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong ${collection} type`);
|
||||
|
|
@ -199,7 +201,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
}
|
||||
|
||||
if (!(typeof x.preferredUsername === 'string' && x.preferredUsername.length > 0 && x.preferredUsername.length <= 128 && /^\w([\w-.]*\w)?$/.test(x.preferredUsername))) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong username`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong username`);
|
||||
}
|
||||
|
||||
// These fields are only informational, and some AP software allows these
|
||||
|
|
@ -207,7 +209,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
// we can at least see these users and their activities.
|
||||
if (x.name) {
|
||||
if (!(typeof x.name === 'string' && x.name.length > 0)) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong name`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong name`);
|
||||
}
|
||||
x.name = truncate(x.name, nameLength);
|
||||
} else if (x.name === '') {
|
||||
|
|
@ -216,24 +218,24 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
}
|
||||
if (x.summary) {
|
||||
if (!(typeof x.summary === 'string' && x.summary.length > 0)) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong summary`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong summary`);
|
||||
}
|
||||
x.summary = truncate(x.summary, summaryLength);
|
||||
}
|
||||
|
||||
const idHost = this.utilityService.punyHostPSLDomain(x.id);
|
||||
if (idHost !== expectHost) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong id ${x.id}`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong id ${x.id}`);
|
||||
}
|
||||
|
||||
if (x.publicKey) {
|
||||
if (typeof x.publicKey.id !== 'string') {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong publicKey.id type`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong publicKey.id type`);
|
||||
}
|
||||
|
||||
const publicKeyIdHost = this.utilityService.punyHostPSLDomain(x.publicKey.id);
|
||||
if (publicKeyIdHost !== expectHost) {
|
||||
throw new UnrecoverableError(`invalid Actor ${uri} - wrong publicKey.id ${x.publicKey.id}`);
|
||||
throw new UnrecoverableError(`invalid Actor ${uri}: wrong publicKey.id ${x.publicKey.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -271,8 +273,6 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
}
|
||||
|
||||
private async resolveAvatarAndBanner(user: MiRemoteUser, icon: any, image: any, bgimg: any): Promise<Partial<Pick<MiRemoteUser, 'avatarId' | 'bannerId' | 'backgroundId' | 'avatarUrl' | 'bannerUrl' | 'backgroundUrl' | 'avatarBlurhash' | 'bannerBlurhash' | 'backgroundBlurhash'>>> {
|
||||
if (user == null) throw new Error('failed to create user: user is null');
|
||||
|
||||
const [avatar, banner, background] = await Promise.all([icon, image, bgimg].map(img => {
|
||||
// icon and image may be arrays
|
||||
// see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon
|
||||
|
|
@ -325,12 +325,11 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
*/
|
||||
@bindThis
|
||||
public async createPerson(uri: string, resolver?: Resolver): Promise<MiRemoteUser> {
|
||||
if (typeof uri !== 'string') throw new UnrecoverableError(`uri is not string: ${uri}`);
|
||||
if (typeof uri !== 'string') throw new UnrecoverableError(`failed to create user ${uri}: input is not string`);
|
||||
|
||||
const host = this.utilityService.punyHost(uri);
|
||||
if (host === this.utilityService.toPuny(this.config.host)) {
|
||||
// TODO convert to unrecoverable error
|
||||
throw new StatusError(`cannot resolve local user: ${uri}`, 400, 'cannot resolve local user');
|
||||
throw new UnrecoverableError(`failed to create user ${uri}: URI is local`);
|
||||
}
|
||||
|
||||
return await this._createPerson(uri, resolver);
|
||||
|
|
@ -340,8 +339,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
const uri = getApId(value);
|
||||
const host = this.utilityService.punyHost(uri);
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
if (resolver == null) resolver = this.apResolverService.createResolver();
|
||||
resolver ??= this.apResolverService.createResolver();
|
||||
|
||||
const object = await resolver.resolve(value);
|
||||
const person = this.validateActor(object, uri);
|
||||
|
|
@ -361,9 +359,11 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
].map((p): Promise<'public' | 'private'> => p
|
||||
.then(isPublic => isPublic ? 'public' : 'private')
|
||||
.catch(err => {
|
||||
if (!(err instanceof StatusError) || err.isRetryable) {
|
||||
this.logger.error('error occurred while fetching following/followers collection', { stack: err });
|
||||
// Permanent error implies hidden or inaccessible, which is a normal thing.
|
||||
if (isRetryableError(err)) {
|
||||
this.logger.error(`error occurred while fetching following/followers collection: ${renderInlineError(err)}`);
|
||||
}
|
||||
|
||||
return 'private';
|
||||
}),
|
||||
),
|
||||
|
|
@ -372,7 +372,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
const bday = person['vcard:bday']?.match(/^\d{4}-\d{2}-\d{2}/);
|
||||
|
||||
if (person.id == null) {
|
||||
throw new UnrecoverableError(`Refusing to create person without id: ${uri}`);
|
||||
throw new UnrecoverableError(`failed to create user ${uri}: missing ID`);
|
||||
}
|
||||
|
||||
const url = this.apUtilityService.findBestObjectUrl(person);
|
||||
|
|
@ -387,7 +387,10 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
const emojis = await this.apNoteService.extractEmojis(person.tag ?? [], host)
|
||||
.then(_emojis => _emojis.map(emoji => emoji.name))
|
||||
.catch(err => {
|
||||
this.logger.error('error occurred while fetching user emojis', { stack: err });
|
||||
// Permanent error implies hidden or inaccessible, which is a normal thing.
|
||||
if (isRetryableError(err)) {
|
||||
this.logger.error(`error occurred while fetching user emojis: ${renderInlineError(err)}`);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
//#endregion
|
||||
|
|
@ -493,7 +496,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
user = u as MiRemoteUser;
|
||||
publicKey = await this.userPublickeysRepository.findOneBy({ userId: user.id });
|
||||
} else {
|
||||
this.logger.error(e instanceof Error ? e : new Error(e as string));
|
||||
this.logger.error('Error creating Person:', e instanceof Error ? e : new Error(e as string));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
@ -533,11 +536,19 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
// Register to the cache
|
||||
this.cacheService.uriPersonCache.set(user.uri, user);
|
||||
} catch (err) {
|
||||
this.logger.error('error occurred while fetching user avatar/banner', { stack: err });
|
||||
// Permanent error implies hidden or inaccessible, which is a normal thing.
|
||||
if (isRetryableError(err)) {
|
||||
this.logger.error(`error occurred while fetching user avatar/banner: ${renderInlineError(err)}`);
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
|
||||
await this.updateFeatured(user.id, resolver).catch(err => this.logger.error(err));
|
||||
await this.updateFeatured(user.id, resolver).catch(err => {
|
||||
// Permanent error implies hidden or inaccessible, which is a normal thing.
|
||||
if (isRetryableError(err)) {
|
||||
this.logger.error(`Error updating featured notes: ${renderInlineError(err)}`);
|
||||
}
|
||||
});
|
||||
|
||||
return user;
|
||||
}
|
||||
|
|
@ -554,7 +565,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
*/
|
||||
@bindThis
|
||||
public async updatePerson(uri: string, resolver?: Resolver | null, hint?: IObject, movePreventUris: string[] = []): Promise<string | void> {
|
||||
if (typeof uri !== 'string') throw new UnrecoverableError('uri is not string');
|
||||
if (typeof uri !== 'string') throw new UnrecoverableError(`failed to update user ${uri}: input is not string`);
|
||||
|
||||
// URIがこのサーバーを指しているならスキップ
|
||||
if (this.utilityService.isUriLocal(uri)) return;
|
||||
|
|
@ -574,8 +585,11 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
this.logger.info(`Updating the Person: ${person.id}`);
|
||||
|
||||
// カスタム絵文字取得
|
||||
const emojis = await this.apNoteService.extractEmojis(person.tag ?? [], exist.host).catch(e => {
|
||||
this.logger.info(`extractEmojis: ${e}`);
|
||||
const emojis = await this.apNoteService.extractEmojis(person.tag ?? [], exist.host).catch(err => {
|
||||
// Permanent error implies hidden or inaccessible, which is a normal thing.
|
||||
if (isRetryableError(err)) {
|
||||
this.logger.error(`error occurred while fetching user emojis: ${renderInlineError(err)}`);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
|
|
@ -592,11 +606,13 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
].map((p): Promise<'public' | 'private' | undefined> => p
|
||||
.then(isPublic => isPublic ? 'public' : 'private')
|
||||
.catch(err => {
|
||||
if (!(err instanceof StatusError) || err.isRetryable) {
|
||||
this.logger.error('error occurred while fetching following/followers collection', { stack: err });
|
||||
// Permanent error implies hidden or inaccessible, which is a normal thing.
|
||||
if (isRetryableError(err)) {
|
||||
this.logger.error(`error occurred while fetching following/followers collection: ${renderInlineError(err)}`);
|
||||
// Do not update the visibility on transient errors.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return 'private';
|
||||
}),
|
||||
),
|
||||
|
|
@ -605,7 +621,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
const bday = person['vcard:bday']?.match(/^\d{4}-\d{2}-\d{2}/);
|
||||
|
||||
if (person.id == null) {
|
||||
throw new UnrecoverableError(`Refusing to update person without id: ${uri}`);
|
||||
throw new UnrecoverableError(`failed to update user ${uri}: missing ID`);
|
||||
}
|
||||
|
||||
const url = this.apUtilityService.findBestObjectUrl(person);
|
||||
|
|
@ -638,7 +654,15 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
.filter((a: unknown) => typeof(a) === 'string' && a.length > 0 && a.length <= 128)
|
||||
.slice(0, 32)
|
||||
: [],
|
||||
...(await this.resolveAvatarAndBanner(exist, person.icon, person.image, person.backgroundUrl).catch(() => ({}))),
|
||||
...(await this.resolveAvatarAndBanner(exist, person.icon, person.image, person.backgroundUrl).catch(err => {
|
||||
// Permanent error implies hidden or inaccessible, which is a normal thing.
|
||||
if (isRetryableError(err)) {
|
||||
this.logger.error(`error occurred while fetching user avatar/banner: ${renderInlineError(err)}`);
|
||||
}
|
||||
|
||||
// Can't return null or destructuring operator will break
|
||||
return {};
|
||||
})),
|
||||
} as Partial<MiRemoteUser> & Pick<MiRemoteUser, 'isBot' | 'isCat' | 'speakAsCat' | 'isLocked' | 'movedToUri' | 'alsoKnownAs' | 'isExplorable'>;
|
||||
|
||||
const moving = ((): boolean => {
|
||||
|
|
@ -722,7 +746,12 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
{ followerSharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox ?? null },
|
||||
);
|
||||
|
||||
await this.updateFeatured(exist.id, resolver).catch(err => this.logger.error(err));
|
||||
await this.updateFeatured(exist.id, resolver).catch(err => {
|
||||
// Permanent error implies hidden or inaccessible, which is a normal thing.
|
||||
if (isRetryableError(err)) {
|
||||
this.logger.error(`Error updating featured notes: ${renderInlineError(err)}`);
|
||||
}
|
||||
});
|
||||
|
||||
const updated = { ...exist, ...updates };
|
||||
|
||||
|
|
@ -761,8 +790,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
const uri = getApId(value);
|
||||
|
||||
if (!this.utilityService.isFederationAllowedUri(uri)) {
|
||||
// TODO convert to identifiable error
|
||||
throw new StatusError(`blocked host: ${uri}`, 451, 'blocked host');
|
||||
throw new IdentifiableError('590719b3-f51f-48a9-8e7d-6f559ad00e5d', `failed to resolve person ${uri}: host is blocked`);
|
||||
}
|
||||
|
||||
//#region このサーバーに既に登録されていたらそれを返す
|
||||
|
|
@ -772,8 +800,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
|
||||
// Bail if local URI doesn't exist
|
||||
if (this.utilityService.isUriLocal(uri)) {
|
||||
// TODO convert to identifiable error
|
||||
throw new StatusError(`cannot resolve local person: ${uri}`, 400, 'cannot resolve local person');
|
||||
throw new IdentifiableError('efb573fd-6b9e-4912-9348-a02f5603df4f', `failed to resolve person ${uri}: URL is local and does not exist`);
|
||||
}
|
||||
|
||||
const unlock = await this.appLockService.getApLock(uri);
|
||||
|
|
@ -818,15 +845,16 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
|||
|
||||
// Resolve to (Ordered)Collection Object
|
||||
const collection = user.featured ? await _resolver.resolveCollection(user.featured, true, user.uri).catch(err => {
|
||||
if (err instanceof AbortError || err instanceof StatusError) {
|
||||
this.logger.warn(`Failed to update featured notes: ${err.name}: ${err.message}`);
|
||||
} else {
|
||||
this.logger.error('Failed to update featured notes:', err);
|
||||
// Permanent error implies hidden or inaccessible, which is a normal thing.
|
||||
if (isRetryableError(err)) {
|
||||
this.logger.warn(`Failed to update featured notes: ${renderInlineError(err)}`);
|
||||
}
|
||||
|
||||
return null;
|
||||
}) : null;
|
||||
if (!collection) return;
|
||||
|
||||
if (!isCollectionOrOrderedCollection(collection)) throw new UnrecoverableError(`featured ${user.featured} is not Collection or OrderedCollection in ${user.uri}`);
|
||||
if (!isCollectionOrOrderedCollection(collection)) throw new UnrecoverableError(`failed to update user ${user.uri}: featured ${user.featured} is not Collection or OrderedCollection`);
|
||||
|
||||
// Resolve to Object(may be Note) arrays
|
||||
const unresolvedItems = isCollection(collection) ? collection.items : collection.orderedItems;
|
||||
|
|
|
|||
|
|
@ -93,7 +93,6 @@ export class ApQuestionService {
|
|||
// eslint-disable-next-line no-param-reassign
|
||||
if (resolver == null) resolver = this.apResolverService.createResolver();
|
||||
const question = await resolver.resolve(value);
|
||||
this.logger.debug(`fetched question: ${JSON.stringify(question, null, 2)}`);
|
||||
|
||||
if (!isQuestion(question)) throw new UnrecoverableError(`object ${getApType(question)} is not a Question: ${uri}`);
|
||||
|
||||
|
|
|
|||
|
|
@ -75,14 +75,17 @@ export function getOneApId(value: ApObject): string {
|
|||
/**
|
||||
* Get ActivityStreams Object id
|
||||
*/
|
||||
export function getApId(source: string | IObject | [string | IObject]): string {
|
||||
const value = getNullableApId(source);
|
||||
export function getApId(value: string | IObject | [string | IObject], sourceForLogs?: string): string {
|
||||
const id = getNullableApId(value);
|
||||
|
||||
if (value == null) {
|
||||
throw new IdentifiableError('ad2dc287-75c1-44c4-839d-3d2e64576675', `invalid AP object ${value}: missing or invalid id`);
|
||||
if (id == null) {
|
||||
const message = sourceForLogs
|
||||
? `invalid AP object ${value} (sent from ${sourceForLogs}): missing id`
|
||||
: `invalid AP object ${value}: missing id`;
|
||||
throw new IdentifiableError('ad2dc287-75c1-44c4-839d-3d2e64576675', message);
|
||||
}
|
||||
|
||||
return value;
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue