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