Skip to content

Commit

Permalink
Fix attachment/Document detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Apr 20, 2024
1 parent 8a854f7 commit 37b0532
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/remote/activitypub/models/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@ import { apLogger } from '../logger';
import { DriveFile } from '../../../models/entities/drive-file';
import { DriveFiles } from '../../../models';
import { ensure } from '../../../prelude/ensure';
import { isDocument } from '../type';

const logger = apLogger;

/**
* Imageを作成します。
*/
export async function createImage(actor: IRemoteUser, value: any): Promise<DriveFile> {
export async function createImage(actor: IRemoteUser, value: any): Promise<DriveFile | null | undefined> {
// 投稿者が凍結されていたらスキップ
if (actor.isSuspended) {
throw new Error('actor has been suspended');
}

const image = await new Resolver().resolve(value) as any;

if (!isDocument(image)) return null;

if (image.url == null) {
throw new Error('invalid image: url not privided');
return null;
}

logger.info(`Creating the Image: ${image.url}`);
Expand Down Expand Up @@ -53,7 +56,7 @@ export async function createImage(actor: IRemoteUser, value: any): Promise<Drive
* Misskeyに対象のImageが登録されていればそれを返し、そうでなければ
* リモートサーバーからフェッチしてMisskeyに登録しそれを返します。
*/
export async function resolveImage(actor: IRemoteUser, value: any): Promise<DriveFile> {
export async function resolveImage(actor: IRemoteUser, value: any): Promise<DriveFile | null | undefined> {
// TODO

// リモートサーバーからフェッチしてきて登録
Expand Down
7 changes: 7 additions & 0 deletions src/remote/activitypub/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ export const isOrderedCollection = (object: IObject): object is IOrderedCollecti
export const isCollectionOrOrderedCollection = (object: IObject): object is ICollection | IOrderedCollection =>
isCollection(object) || isOrderedCollection(object);

export interface IApDocument extends IObject {
type: 'Audio' | 'Document' | 'Image' | 'Page' | 'Video';
}

export const isDocument = (object: IObject): object is IApDocument =>
['Audio', 'Document', 'Image', 'Page', 'Video'].includes(getApType(object));

export interface IApPropertyValue extends IObject {
type: 'PropertyValue';
identifier: IApPropertyValue;
Expand Down

0 comments on commit 37b0532

Please # to comment.