mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Add stricter ESLint rules
This commit is contained in:
parent
887128356e
commit
e618996936
|
|
@ -3,6 +3,7 @@ module.exports = {
|
||||||
"eslint:recommended",
|
"eslint:recommended",
|
||||||
"plugin:@typescript-eslint/strict-type-checked",
|
"plugin:@typescript-eslint/strict-type-checked",
|
||||||
"plugin:@typescript-eslint/stylistic",
|
"plugin:@typescript-eslint/stylistic",
|
||||||
|
"plugin:prettier/recommended",
|
||||||
],
|
],
|
||||||
parser: "@typescript-eslint/parser",
|
parser: "@typescript-eslint/parser",
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
|
|
|
||||||
9
.prettierrc
Normal file
9
.prettierrc
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"tabWidth": 4,
|
||||||
|
"useTabs": true,
|
||||||
|
"arrowParens": "avoid",
|
||||||
|
"bracketSameLine": true,
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"jsxSingleQuote": false,
|
||||||
|
"trailingComma": "es5"
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,6 @@ export class Application extends BaseEntity {
|
||||||
name: "",
|
name: "",
|
||||||
website: null,
|
website: null,
|
||||||
vapid_key: null,
|
vapid_key: null,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,6 @@ export class Emoji extends BaseEntity {
|
||||||
url: "",
|
url: "",
|
||||||
visible_in_picker: false,
|
visible_in_picker: false,
|
||||||
category: undefined,
|
category: undefined,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,10 @@
|
||||||
import { BaseEntity, Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
import {
|
||||||
|
BaseEntity,
|
||||||
|
Column,
|
||||||
|
Entity,
|
||||||
|
ManyToOne,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
} from "typeorm";
|
||||||
import { User } from "./User";
|
import { User } from "./User";
|
||||||
import { Status } from "./Status";
|
import { Status } from "./Status";
|
||||||
|
|
||||||
|
|
@ -12,12 +18,12 @@ export class Favourite extends BaseEntity {
|
||||||
@PrimaryGeneratedColumn("uuid")
|
@PrimaryGeneratedColumn("uuid")
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
@ManyToOne(() => User, (user) => user.id)
|
@ManyToOne(() => User, user => user.id)
|
||||||
actor!: User;
|
actor!: User;
|
||||||
|
|
||||||
@ManyToOne(() => Status, (status) => status.id)
|
@ManyToOne(() => Status, status => status.id)
|
||||||
object!: Status;
|
object!: Status;
|
||||||
|
|
||||||
@Column("datetime")
|
@Column("datetime")
|
||||||
published!: Date;
|
published!: Date;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,10 @@
|
||||||
import { BaseEntity, Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
import {
|
||||||
|
BaseEntity,
|
||||||
|
Column,
|
||||||
|
Entity,
|
||||||
|
ManyToOne,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
} from "typeorm";
|
||||||
import { APIInstance } from "~types/entities/instance";
|
import { APIInstance } from "~types/entities/instance";
|
||||||
import { User } from "./User";
|
import { User } from "./User";
|
||||||
|
|
||||||
|
|
@ -9,7 +15,7 @@ export class Instance extends BaseEntity {
|
||||||
@PrimaryGeneratedColumn("uuid")
|
@PrimaryGeneratedColumn("uuid")
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
@ManyToOne(() => User, (user) => user.id)
|
@ManyToOne(() => User, user => user.id)
|
||||||
contact_account!: User;
|
contact_account!: User;
|
||||||
|
|
||||||
@Column("jsonb", {
|
@Column("jsonb", {
|
||||||
|
|
@ -63,4 +69,4 @@ export class Instance extends BaseEntity {
|
||||||
max_toot_chars: 0,
|
max_toot_chars: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||||
import {
|
import { APObject } from "activitypub-types";
|
||||||
APObject,
|
|
||||||
} from "activitypub-types";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores an ActivityPub object as raw JSON-LD data
|
* Stores an ActivityPub object as raw JSON-LD data
|
||||||
|
|
@ -15,4 +13,4 @@ export class RawObject extends BaseEntity {
|
||||||
|
|
||||||
@Column("json")
|
@Column("json")
|
||||||
data!: APObject;
|
data!: APObject;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,10 @@ export class Renote extends BaseEntity {
|
||||||
@PrimaryGeneratedColumn("uuid")
|
@PrimaryGeneratedColumn("uuid")
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
@ManyToOne(() => User, (user) => user.id)
|
@ManyToOne(() => User, user => user.id)
|
||||||
actor!: User;
|
actor!: User;
|
||||||
|
|
||||||
@ManyToOne(() => Status, (status) => status.id)
|
@ManyToOne(() => Status, status => status.id)
|
||||||
object!: Status;
|
object!: Status;
|
||||||
|
|
||||||
@Column("datetime")
|
@Column("datetime")
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ export class Status extends BaseEntity {
|
||||||
@PrimaryGeneratedColumn("uuid")
|
@PrimaryGeneratedColumn("uuid")
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
@ManyToOne(() => User, (user) => user.id)
|
@ManyToOne(() => User, user => user.id)
|
||||||
account!: User;
|
account!: User;
|
||||||
|
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
|
|
@ -36,7 +36,7 @@ export class Status extends BaseEntity {
|
||||||
@UpdateDateColumn()
|
@UpdateDateColumn()
|
||||||
updated_at!: Date;
|
updated_at!: Date;
|
||||||
|
|
||||||
@ManyToOne(() => Status, (status) => status.id, {
|
@ManyToOne(() => Status, status => status.id, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
reblog?: Status;
|
reblog?: Status;
|
||||||
|
|
@ -60,31 +60,33 @@ export class Status extends BaseEntity {
|
||||||
})
|
})
|
||||||
spoiler_text!: string;
|
spoiler_text!: string;
|
||||||
|
|
||||||
@ManyToOne(() => Application, (app) => app.id, {
|
@ManyToOne(() => Application, app => app.id, {
|
||||||
nullable: true
|
nullable: true,
|
||||||
})
|
})
|
||||||
application!: Application | null;
|
application!: Application | null;
|
||||||
|
|
||||||
@ManyToMany(() => Emoji, (emoji) => emoji.id)
|
@ManyToMany(() => Emoji, emoji => emoji.id)
|
||||||
emojis!: Emoji[];
|
emojis!: Emoji[];
|
||||||
|
|
||||||
async getFavourites(): Promise<Favourite[]> {
|
async getFavourites(): Promise<Favourite[]> {
|
||||||
return Favourite.find({
|
return Favourite.find({
|
||||||
where: {
|
where: {
|
||||||
object: {
|
object: {
|
||||||
id: this.id
|
id: this.id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async toAPI(): Promise<APIStatus> {
|
async toAPI(): Promise<APIStatus> {
|
||||||
return {
|
return {
|
||||||
account: await this.account.toAPI(),
|
account: await this.account.toAPI(),
|
||||||
application: await this.application?.toAPI() ?? null,
|
application: (await this.application?.toAPI()) ?? null,
|
||||||
bookmarked: false,
|
bookmarked: false,
|
||||||
created_at: this.created_at.toISOString(),
|
created_at: this.created_at.toISOString(),
|
||||||
emojis: await Promise.all(this.emojis.map(async (emoji) => await emoji.toAPI())),
|
emojis: await Promise.all(
|
||||||
|
this.emojis.map(async emoji => await emoji.toAPI())
|
||||||
|
),
|
||||||
favourited: false,
|
favourited: false,
|
||||||
favourites_count: (await this.getFavourites()).length,
|
favourites_count: (await this.getFavourites()).length,
|
||||||
id: this.id,
|
id: this.id,
|
||||||
|
|
@ -96,7 +98,7 @@ export class Status extends BaseEntity {
|
||||||
muted: false,
|
muted: false,
|
||||||
pinned: false,
|
pinned: false,
|
||||||
poll: null,
|
poll: null,
|
||||||
reblog: this.isReblog ? await this.reblog?.toAPI() ?? null : null,
|
reblog: this.isReblog ? (await this.reblog?.toAPI()) ?? null : null,
|
||||||
reblogged: false,
|
reblogged: false,
|
||||||
reblogs_count: 0,
|
reblogs_count: 0,
|
||||||
replies_count: 0,
|
replies_count: 0,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
import { getConfig, getHost } from "@config";
|
import { getConfig, getHost } from "@config";
|
||||||
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
import {
|
||||||
|
BaseEntity,
|
||||||
|
Column,
|
||||||
|
CreateDateColumn,
|
||||||
|
Entity,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
} from "typeorm";
|
||||||
import { APIAccount } from "~types/entities/account";
|
import { APIAccount } from "~types/entities/account";
|
||||||
|
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
|
|
@ -73,6 +80,6 @@ export class User extends BaseEntity {
|
||||||
discoverable: undefined,
|
discoverable: undefined,
|
||||||
role: undefined,
|
role: undefined,
|
||||||
mute_expires_at: undefined,
|
mute_expires_at: undefined,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
index.ts
9
index.ts
|
|
@ -4,7 +4,7 @@ import "reflect-metadata";
|
||||||
const router = new Bun.FileSystemRouter({
|
const router = new Bun.FileSystemRouter({
|
||||||
style: "nextjs",
|
style: "nextjs",
|
||||||
dir: process.cwd() + "/server/api",
|
dir: process.cwd() + "/server/api",
|
||||||
})
|
});
|
||||||
|
|
||||||
console.log("[+] Starting FediProject...");
|
console.log("[+] Starting FediProject...");
|
||||||
|
|
||||||
|
|
@ -18,7 +18,10 @@ Bun.serve({
|
||||||
|
|
||||||
if (matchedRoute) {
|
if (matchedRoute) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||||
return (await import(matchedRoute.filePath)).default(req, matchedRoute) as Response | Promise<Response>;
|
return (await import(matchedRoute.filePath)).default(
|
||||||
|
req,
|
||||||
|
matchedRoute
|
||||||
|
) as Response | Promise<Response>;
|
||||||
} else {
|
} else {
|
||||||
return new Response(undefined, {
|
return new Response(undefined, {
|
||||||
status: 404,
|
status: 404,
|
||||||
|
|
@ -28,4 +31,4 @@ Bun.serve({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[+] FediProject started!")
|
console.log("[+] FediProject started!");
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,11 @@
|
||||||
"activitypub-types": "^1.0.3",
|
"activitypub-types": "^1.0.3",
|
||||||
"bun-types": "latest",
|
"bun-types": "latest",
|
||||||
"eslint": "^8.49.0",
|
"eslint": "^8.49.0",
|
||||||
|
"eslint-config-prettier": "^9.0.0",
|
||||||
|
"eslint-formatter-pretty": "^5.0.0",
|
||||||
|
"eslint-formatter-summary": "^1.1.0",
|
||||||
|
"eslint-plugin-prettier": "^5.0.0",
|
||||||
|
"prettier": "^3.0.3",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -42,19 +42,21 @@ export default async (
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const lastPost = (await RawObject.find({
|
const lastPost = (
|
||||||
where: {
|
await RawObject.find({
|
||||||
data: {
|
where: {
|
||||||
attributedTo: `${getHost()}/@${user.username}`,
|
data: {
|
||||||
|
attributedTo: `${getHost()}/@${user.username}`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
order: {
|
||||||
order: {
|
data: {
|
||||||
data: {
|
published: "ASC",
|
||||||
published: "ASC",
|
},
|
||||||
},
|
},
|
||||||
},
|
take: 1,
|
||||||
take: 1,
|
})
|
||||||
}))[0];
|
)[0];
|
||||||
|
|
||||||
if (!page)
|
if (!page)
|
||||||
return jsonLdResponse(
|
return jsonLdResponse(
|
||||||
|
|
@ -73,7 +75,7 @@ export default async (
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
else {
|
else {
|
||||||
let posts: RawObject[] = []
|
let posts: RawObject[] = [];
|
||||||
|
|
||||||
if (min_id) {
|
if (min_id) {
|
||||||
posts = await RawObject.find({
|
posts = await RawObject.find({
|
||||||
|
|
@ -107,8 +109,6 @@ export default async (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return jsonLdResponse(
|
return jsonLdResponse(
|
||||||
await compact({
|
await compact({
|
||||||
"@context": [
|
"@context": [
|
||||||
|
|
@ -145,7 +145,7 @@ export default async (
|
||||||
}&page=true`,
|
}&page=true`,
|
||||||
orderedItems: posts
|
orderedItems: posts
|
||||||
.slice(0, 10)
|
.slice(0, 10)
|
||||||
.map((post) => post.data) as NodeObject[],
|
.map(post => post.data) as NodeObject[],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@ export default async (
|
||||||
matchedRoute: MatchedRoute
|
matchedRoute: MatchedRoute
|
||||||
): Promise<Response> => {
|
): Promise<Response> => {
|
||||||
const object = await RawObject.findOneBy({
|
const object = await RawObject.findOneBy({
|
||||||
id: matchedRoute.params.id
|
id: matchedRoute.params.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!object) return errorResponse("Object not found", 404)
|
if (!object) return errorResponse("Object not found", 404);
|
||||||
|
|
||||||
return jsonLdResponse(object);
|
return jsonLdResponse(object);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@ export default async (
|
||||||
id,
|
id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user)
|
if (!user) return errorResponse("User not found", 404);
|
||||||
return errorResponse("User not found", 404)
|
|
||||||
|
|
||||||
return jsonResponse(user.toAPI());
|
return jsonResponse(user.toAPI());
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,20 +7,20 @@ export interface ConfigType {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
database: string;
|
database: string;
|
||||||
}
|
};
|
||||||
http: {
|
http: {
|
||||||
port: number;
|
port: number;
|
||||||
base_url: string;
|
base_url: string;
|
||||||
}
|
};
|
||||||
[ key: string ]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getConfig = () => {
|
export const getConfig = () => {
|
||||||
return data as ConfigType;
|
return data as ConfigType;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getHost = () => {
|
export const getHost = () => {
|
||||||
const url = new URL(getConfig().http.base_url);
|
const url = new URL(getConfig().http.base_url);
|
||||||
|
|
||||||
return url.host;
|
return url.host;
|
||||||
}
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ import { NodeObject } from "jsonld";
|
||||||
export const jsonResponse = (data: object, status = 200) => {
|
export const jsonResponse = (data: object, status = 200) => {
|
||||||
return new Response(JSON.stringify(data), {
|
return new Response(JSON.stringify(data), {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
status,
|
status,
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export const jsonLdResponse = (data: NodeObject | APObject, status = 200) => {
|
export const jsonLdResponse = (data: NodeObject | APObject, status = 200) => {
|
||||||
return new Response(JSON.stringify(data), {
|
return new Response(JSON.stringify(data), {
|
||||||
|
|
@ -20,7 +20,10 @@ export const jsonLdResponse = (data: NodeObject | APObject, status = 200) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const errorResponse = (error: string, status = 500) => {
|
export const errorResponse = (error: string, status = 500) => {
|
||||||
return jsonResponse({
|
return jsonResponse(
|
||||||
error: error
|
{
|
||||||
}, status);
|
error: error,
|
||||||
}
|
},
|
||||||
|
status
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue