add: filter endpoint to masto api
This commit is contained in:
parent
4e375f303f
commit
34e6717dab
2 changed files with 125 additions and 0 deletions
66
packages/backend/src/server/api/mastodon/endpoints/filter.ts
Normal file
66
packages/backend/src/server/api/mastodon/endpoints/filter.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import type { MegalodonInterface } from "megalodon";
|
||||
import type { FastifyRequest } from 'fastify';
|
||||
import { convertTimelinesArgsId } from "./timeline.js";
|
||||
import { IdConvertType as IdType, convertId, convertFilter } from '../converters.js';
|
||||
|
||||
export class apiFilterMastodon {
|
||||
private request: FastifyRequest;
|
||||
private client: MegalodonInterface;
|
||||
|
||||
constructor(request: FastifyRequest, client: MegalodonInterface) {
|
||||
this.request = request;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public async getFilters() {
|
||||
try {
|
||||
const data = await this.client.getFilters();
|
||||
return data.data.map((filter) => convertFilter(filter));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async getFilter() {
|
||||
try {
|
||||
const data = await this.client.getFilter( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
return convertFilter(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async createFilter() {
|
||||
try {
|
||||
const body: any = this.request.body;
|
||||
const data = await this.client.createFilter(body.pharse, body.context, body);
|
||||
return convertFilter(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async updateFilter() {
|
||||
try {
|
||||
const body: any = this.request.body;
|
||||
const data = await this.client.updateFilter(convertId((this.request.params as any).id, IdType.SharkeyId), body.pharse, body.context);
|
||||
return convertFilter(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async rmFilter() {
|
||||
try {
|
||||
const data = await this.client.deleteFilter( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
return data.data;
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue