chore: lint and update package name
This commit is contained in:
parent
410e6515d3
commit
db6dc1b52e
12 changed files with 1636 additions and 1683 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { convertId, IdConvertType as IdType, convertAccount, convertRelationship, convertStatus } from '../converters.js';
|
||||
import { argsToBools, convertTimelinesArgsId, limitToInt } from './timeline.js';
|
||||
import type { MegalodonInterface } from 'megalodon';
|
||||
import type { FastifyRequest } from 'fastify';
|
||||
import { argsToBools, convertTimelinesArgsId, limitToInt } from './timeline.js';
|
||||
import { convertId, IdConvertType as IdType, convertAccount, convertRelationship, convertStatus } from '../converters.js';
|
||||
|
||||
const relationshipModel = {
|
||||
id: '',
|
||||
|
|
@ -20,21 +20,21 @@ const relationshipModel = {
|
|||
note: '',
|
||||
};
|
||||
|
||||
export class apiAccountMastodon {
|
||||
private request: FastifyRequest;
|
||||
private client: MegalodonInterface;
|
||||
private BASE_URL: string;
|
||||
export class ApiAccountMastodon {
|
||||
private request: FastifyRequest;
|
||||
private client: MegalodonInterface;
|
||||
private BASE_URL: string;
|
||||
|
||||
constructor(request: FastifyRequest, client: MegalodonInterface, BASE_URL: string) {
|
||||
this.request = request;
|
||||
this.client = client;
|
||||
this.BASE_URL = BASE_URL;
|
||||
}
|
||||
constructor(request: FastifyRequest, client: MegalodonInterface, BASE_URL: string) {
|
||||
this.request = request;
|
||||
this.client = client;
|
||||
this.BASE_URL = BASE_URL;
|
||||
}
|
||||
|
||||
public async verifyCredentials() {
|
||||
try {
|
||||
public async verifyCredentials() {
|
||||
try {
|
||||
const data = await this.client.verifyAccountCredentials();
|
||||
let acct = data.data;
|
||||
const acct = data.data;
|
||||
acct.id = convertId(acct.id, IdType.MastodonId);
|
||||
acct.display_name = acct.display_name || acct.username;
|
||||
acct.url = `${this.BASE_URL}/@${acct.url}`;
|
||||
|
|
@ -56,230 +56,230 @@ export class apiAccountMastodon {
|
|||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async updateCredentials() {
|
||||
try {
|
||||
const data = await this.client.updateCredentials(this.request.body as any);
|
||||
return convertAccount(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
public async updateCredentials() {
|
||||
try {
|
||||
const data = await this.client.updateCredentials(this.request.body as any);
|
||||
return convertAccount(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async lookup() {
|
||||
try {
|
||||
const data = await this.client.search((this.request.query as any).acct, { type: 'accounts' });
|
||||
return convertAccount(data.data.accounts[0]);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
public async lookup() {
|
||||
try {
|
||||
const data = await this.client.search((this.request.query as any).acct, { type: 'accounts' });
|
||||
return convertAccount(data.data.accounts[0]);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async getRelationships(users: [string]) {
|
||||
try {
|
||||
relationshipModel.id = users?.toString() || '1';
|
||||
public async getRelationships(users: [string]) {
|
||||
try {
|
||||
relationshipModel.id = users.toString() || '1';
|
||||
|
||||
if (!users) {
|
||||
if (!(users.length > 0)) {
|
||||
return [relationshipModel];
|
||||
}
|
||||
|
||||
let reqIds = [];
|
||||
const reqIds = [];
|
||||
for (let i = 0; i < users.length; i++) {
|
||||
reqIds.push(convertId(users[i], IdType.SharkeyId));
|
||||
}
|
||||
|
||||
const data = await this.client.getRelationships(reqIds);
|
||||
return data.data.map((relationship) => convertRelationship(relationship));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async getStatuses() {
|
||||
try {
|
||||
const data = await this.client.getAccountStatuses(
|
||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||
convertTimelinesArgsId(argsToBools(limitToInt(this.request.query as any)))
|
||||
);
|
||||
public async getStatuses() {
|
||||
try {
|
||||
const data = await this.client.getAccountStatuses(
|
||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||
convertTimelinesArgsId(argsToBools(limitToInt(this.request.query as any))),
|
||||
);
|
||||
return data.data.map((status) => convertStatus(status));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async getFollowers() {
|
||||
try {
|
||||
const data = await this.client.getAccountFollowers(
|
||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||
convertTimelinesArgsId(limitToInt(this.request.query as any))
|
||||
);
|
||||
public async getFollowers() {
|
||||
try {
|
||||
const data = await this.client.getAccountFollowers(
|
||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||
convertTimelinesArgsId(limitToInt(this.request.query as any)),
|
||||
);
|
||||
return data.data.map((account) => convertAccount(account));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async getFollowing() {
|
||||
try {
|
||||
const data = await this.client.getAccountFollowing(
|
||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||
convertTimelinesArgsId(limitToInt(this.request.query as any))
|
||||
);
|
||||
public async getFollowing() {
|
||||
try {
|
||||
const data = await this.client.getAccountFollowing(
|
||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||
convertTimelinesArgsId(limitToInt(this.request.query as any)),
|
||||
);
|
||||
return data.data.map((account) => convertAccount(account));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async addFollow() {
|
||||
try {
|
||||
const data = await this.client.followAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
let acct = convertRelationship(data.data);
|
||||
acct.following = true;
|
||||
public async addFollow() {
|
||||
try {
|
||||
const data = await this.client.followAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
const acct = convertRelationship(data.data);
|
||||
acct.following = true;
|
||||
return acct;
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async rmFollow() {
|
||||
try {
|
||||
const data = await this.client.unfollowAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
let acct = convertRelationship(data.data);
|
||||
acct.following = false;
|
||||
public async rmFollow() {
|
||||
try {
|
||||
const data = await this.client.unfollowAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
const acct = convertRelationship(data.data);
|
||||
acct.following = false;
|
||||
return acct;
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async addBlock() {
|
||||
try {
|
||||
const data = await this.client.blockAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
public async addBlock() {
|
||||
try {
|
||||
const data = await this.client.blockAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
return convertRelationship(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async rmBlock() {
|
||||
try {
|
||||
const data = await this.client.unblockAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
public async rmBlock() {
|
||||
try {
|
||||
const data = await this.client.unblockAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
return convertRelationship(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async addMute() {
|
||||
try {
|
||||
const data = await this.client.muteAccount(
|
||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||
this.request.body as any
|
||||
);
|
||||
public async addMute() {
|
||||
try {
|
||||
const data = await this.client.muteAccount(
|
||||
convertId((this.request.params as any).id, IdType.SharkeyId),
|
||||
this.request.body as any,
|
||||
);
|
||||
return convertRelationship(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async rmMute() {
|
||||
try {
|
||||
const data = await this.client.unmuteAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
public async rmMute() {
|
||||
try {
|
||||
const data = await this.client.unmuteAccount( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
return convertRelationship(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async getBookmarks() {
|
||||
try {
|
||||
const data = await this.client.getBookmarks( convertTimelinesArgsId(limitToInt(this.request.query as any)) );
|
||||
public async getBookmarks() {
|
||||
try {
|
||||
const data = await this.client.getBookmarks( convertTimelinesArgsId(limitToInt(this.request.query as any)) );
|
||||
return data.data.map((status) => convertStatus(status));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async getFavourites() {
|
||||
try {
|
||||
const data = await this.client.getFavourites( convertTimelinesArgsId(limitToInt(this.request.query as any)) );
|
||||
public async getFavourites() {
|
||||
try {
|
||||
const data = await this.client.getFavourites( convertTimelinesArgsId(limitToInt(this.request.query as any)) );
|
||||
return data.data.map((status) => convertStatus(status));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async getMutes() {
|
||||
try {
|
||||
const data = await this.client.getMutes( convertTimelinesArgsId(limitToInt(this.request.query as any)) );
|
||||
public async getMutes() {
|
||||
try {
|
||||
const data = await this.client.getMutes( convertTimelinesArgsId(limitToInt(this.request.query as any)) );
|
||||
return data.data.map((account) => convertAccount(account));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async getBlocks() {
|
||||
try {
|
||||
const data = await this.client.getBlocks( convertTimelinesArgsId(limitToInt(this.request.query as any)) );
|
||||
public async getBlocks() {
|
||||
try {
|
||||
const data = await this.client.getBlocks( convertTimelinesArgsId(limitToInt(this.request.query as any)) );
|
||||
return data.data.map((account) => convertAccount(account));
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async acceptFollow() {
|
||||
try {
|
||||
const data = await this.client.acceptFollowRequest( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
public async acceptFollow() {
|
||||
try {
|
||||
const data = await this.client.acceptFollowRequest( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
return convertRelationship(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
|
||||
public async rejectFollow() {
|
||||
try {
|
||||
const data = await this.client.rejectFollowRequest( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
public async rejectFollow() {
|
||||
try {
|
||||
const data = await this.client.rejectFollowRequest( convertId((this.request.params as any).id, IdType.SharkeyId) );
|
||||
return convertRelationship(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return e.response.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue