Skip to content

Commit

Permalink
Fix attachment/Document detection
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed May 1, 2024
1 parent f6579ad commit e3bdab7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 7 additions & 4 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,8 +56,8 @@ export async function createImage(actor: IRemoteUser, value: any): Promise<Drive
* Groundpolisに対象のImageが登録されていればそれを返し、そうでなければ
* リモートサーバーからフェッチしてGroundpolisに登録しそれを返します。
*/
export async function resolveImage(actor: IRemoteUser, value: any): Promise<DriveFile> {
// TODO
export async function resolveImage(actor: IRemoteUser, value: any): Promise<DriveFile | null | undefined> {
// TODO: Misskeyに対象のImageが登録されていればそれを返す

// リモートサーバーからフェッチしてきて登録
return await createImage(actor, value);
Expand Down
8 changes: 8 additions & 0 deletions src/remote/activitypub/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ 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(object.type);

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

0 comments on commit e3bdab7

Please sign in to comment.