diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 00000000..ad661a7a --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,14 @@ +module.exports = { + extends: [ + "eslint:recommended", + "plugin:@typescript-eslint/strict-type-checked", + "plugin:@typescript-eslint/stylistic", + ], + parser: "@typescript-eslint/parser", + parserOptions: { + project: "./tsconfig.json", + }, + ignorePatterns: ["node_modules/", "dist/", ".eslintrc.cjs"], + plugins: ["@typescript-eslint"], + root: true, +}; diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 2eae3cbc..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - extends: [ - "eslint:strict", - "plugin:@typescript-eslint/strict-type-checked", - "plugin:@typescript-eslint/stylistic", - ], -}; diff --git a/bun.lockb b/bun.lockb index 80d18dfd..86abf0f9 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/index.ts b/index.ts index c073b0e5..906dace6 100644 --- a/index.ts +++ b/index.ts @@ -3,21 +3,24 @@ const router = new Bun.FileSystemRouter({ dir: process.cwd() + "/server/api", }) +console.log("[+] Starting FediProject..."); + Bun.serve({ - port: 8080, + port: 8653, hostname: "0.0.0.0", // defaults to "0.0.0.0" async fetch(req) { - const url = new URL(req.url); - const matchedRoute = router.match(req); if (matchedRoute) { - return (await import(matchedRoute.filePath)).default(req, 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; } else { - const response = new Response(undefined, { + return new Response(undefined, { status: 404, statusText: "Route not found", }); } }, }); + +console.log("[+] FediProject started!") diff --git a/package.json b/package.json index 27596bb7..75e85fd0 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,19 @@ { - "name": "fedi-project", - "module": "index.ts", - "type": "module", - "devDependencies": { - "@typescript-eslint/eslint-plugin": "^6.6.0", - "bun-types": "latest", - "eslint": "^8.49.0" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "pg": "^8.11.3", - "typeorm": "^0.3.17" - } -} \ No newline at end of file + "name": "fedi-project", + "module": "index.ts", + "type": "module", + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^6.6.0", + "@typescript-eslint/parser": "^6.6.0", + "bun-types": "latest", + "eslint": "^8.49.0", + "typescript": "^5.2.2" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "dependencies": { + "pg": "^8.11.3", + "typeorm": "^0.3.17" + } +} diff --git a/types/entities/account.ts b/types/entities/account.ts index cf663eda..52a5e532 100644 --- a/types/entities/account.ts +++ b/types/entities/account.ts @@ -3,7 +3,7 @@ import { Field } from "./field"; import { Role } from "./role"; import { Source } from "./source"; -export type Account = { +export interface Account { id: string; username: string; acct: string; @@ -24,11 +24,11 @@ export type Account = { avatar_static: string; header: string; header_static: string; - emojis: Array; + emojis: Emoji[]; moved: Account | null; - fields: Array; + fields: Field[]; bot: boolean; source?: Source; role?: Role; mute_expires_at?: string; -}; +} diff --git a/types/entities/activity.ts b/types/entities/activity.ts index 47647ffd..5e1b4d10 100644 --- a/types/entities/activity.ts +++ b/types/entities/activity.ts @@ -1,6 +1,6 @@ -export type Activity = { +export interface Activity { week: string; statuses: string; logins: string; registrations: string; -}; +} diff --git a/types/entities/announcement.ts b/types/entities/announcement.ts index d954ff82..953c3eb7 100644 --- a/types/entities/announcement.ts +++ b/types/entities/announcement.ts @@ -1,7 +1,7 @@ import { Emoji } from "./emoji"; import { StatusTag } from "./status"; -export type Announcement = { +export interface Announcement { id: string; content: string; starts_at: string | null; @@ -11,29 +11,29 @@ export type Announcement = { published_at: string; updated_at: string; read: boolean | null; - mentions: Array; - statuses: Array; - tags: Array; - emojis: Array; - reactions: Array; -}; + mentions: AnnouncementAccount[]; + statuses: AnnouncementStatus[]; + tags: StatusTag[]; + emojis: Emoji[]; + reactions: AnnouncementReaction[]; +} -export type AnnouncementAccount = { +export interface AnnouncementAccount { id: string; username: string; url: string; acct: string; -}; +} -export type AnnouncementStatus = { +export interface AnnouncementStatus { id: string; url: string; -}; +} -export type AnnouncementReaction = { +export interface AnnouncementReaction { name: string; count: number; me: boolean | null; url: string | null; static_url: string | null; -}; +} diff --git a/types/entities/application.ts b/types/entities/application.ts index 0d17d205..f95d6630 100644 --- a/types/entities/application.ts +++ b/types/entities/application.ts @@ -1,5 +1,5 @@ -export type Application = { +export interface Application { name: string; website?: string | null; vapid_key?: string | null; -}; +} diff --git a/types/entities/async_attachment.ts b/types/entities/async_attachment.ts index f822ab08..71817c1b 100644 --- a/types/entities/async_attachment.ts +++ b/types/entities/async_attachment.ts @@ -1,6 +1,6 @@ import { Meta } from "./attachment"; -export type AsyncAttachment = { +export interface AsyncAttachment { id: string; type: "unknown" | "image" | "gifv" | "video" | "audio"; url: string | null; @@ -10,4 +10,4 @@ export type AsyncAttachment = { meta: Meta | null; description: string | null; blurhash: string | null; -}; +} diff --git a/types/entities/attachment.ts b/types/entities/attachment.ts index e7c40115..2933fd6c 100644 --- a/types/entities/attachment.ts +++ b/types/entities/attachment.ts @@ -1,4 +1,4 @@ -export type Sub = { +export interface Sub { // For Image, Gifv, and Video width?: number; height?: number; @@ -11,14 +11,14 @@ export type Sub = { // For Audio, Gifv, and Video duration?: number; bitrate?: number; -}; +} -export type Focus = { +export interface Focus { x: number; y: number; -}; +} -export type Meta = { +export interface Meta { original?: Sub; small?: Sub; focus?: Focus; @@ -32,9 +32,9 @@ export type Meta = { audio_encode?: string; audio_bitrate?: string; audio_channel?: string; -}; +} -export type Attachment = { +export interface Attachment { id: string; type: "unknown" | "image" | "gifv" | "video" | "audio"; url: string; @@ -44,4 +44,4 @@ export type Attachment = { meta: Meta | null; description: string | null; blurhash: string | null; -}; +} diff --git a/types/entities/card.ts b/types/entities/card.ts index f6513a71..bd496cd9 100644 --- a/types/entities/card.ts +++ b/types/entities/card.ts @@ -1,4 +1,4 @@ -export type Card = { +export interface Card { url: string; title: string; description: string; @@ -13,4 +13,4 @@ export type Card = { height: number; embed_url: string; blurhash: string | null; -}; +} diff --git a/types/entities/context.ts b/types/entities/context.ts index 623a11e0..e73a0180 100644 --- a/types/entities/context.ts +++ b/types/entities/context.ts @@ -1,6 +1,6 @@ import { Status } from "./status"; -export type Context = { - ancestors: Array; - descendants: Array; -}; +export interface Context { + ancestors: Status[]; + descendants: Status[]; +} diff --git a/types/entities/conversation.ts b/types/entities/conversation.ts index fd372f43..d8eeeda3 100644 --- a/types/entities/conversation.ts +++ b/types/entities/conversation.ts @@ -1,9 +1,9 @@ import { Account } from "./account"; import { Status } from "./status"; -export type Conversation = { +export interface Conversation { id: string; - accounts: Array; + accounts: Account[]; last_status: Status | null; unread: boolean; -}; +} diff --git a/types/entities/emoji.ts b/types/entities/emoji.ts index d41b2ab5..32e4437f 100644 --- a/types/entities/emoji.ts +++ b/types/entities/emoji.ts @@ -1,7 +1,7 @@ -export type Emoji = { +export interface Emoji { shortcode: string; static_url: string; url: string; visible_in_picker: boolean; category?: string; -}; +} diff --git a/types/entities/featured_tag.ts b/types/entities/featured_tag.ts index b3479069..765acb0b 100644 --- a/types/entities/featured_tag.ts +++ b/types/entities/featured_tag.ts @@ -1,6 +1,6 @@ -export type FeaturedTag = { +export interface FeaturedTag { id: string; name: string; statuses_count: number; last_status_at: string; -}; +} diff --git a/types/entities/field.ts b/types/entities/field.ts index 44664c08..f5e5cb83 100644 --- a/types/entities/field.ts +++ b/types/entities/field.ts @@ -1,5 +1,5 @@ -export type Field = { +export interface Field { name: string; value: string; verified_at: string | null; -}; +} diff --git a/types/entities/filter.ts b/types/entities/filter.ts index 8e68343c..496dfe4e 100644 --- a/types/entities/filter.ts +++ b/types/entities/filter.ts @@ -1,10 +1,10 @@ -export type Filter = { +export interface Filter { id: string; phrase: string; - context: Array; + context: FilterContext[]; expires_at: string | null; irreversible: boolean; whole_word: boolean; -}; +} export type FilterContext = string; diff --git a/types/entities/history.ts b/types/entities/history.ts index 442e6dc7..4c9d55d3 100644 --- a/types/entities/history.ts +++ b/types/entities/history.ts @@ -1,5 +1,5 @@ -export type History = { +export interface History { day: string; uses: number; accounts: number; -}; +} diff --git a/types/entities/identity_proof.ts b/types/entities/identity_proof.ts index bdf601af..a7aff6e1 100644 --- a/types/entities/identity_proof.ts +++ b/types/entities/identity_proof.ts @@ -1,7 +1,7 @@ -export type IdentityProof = { +export interface IdentityProof { provider: string; provider_username: string; updated_at: string; proof_url: string; profile_url: string; -}; +} \ No newline at end of file diff --git a/types/entities/instance.ts b/types/entities/instance.ts index e3e91ef3..f111c4c5 100644 --- a/types/entities/instance.ts +++ b/types/entities/instance.ts @@ -2,7 +2,7 @@ import { Account } from "./account"; import { Stats } from "./stats"; import { URLs } from "./urls"; -export type Instance = { +export interface Instance { uri: string; title: string; description: string; @@ -11,7 +11,7 @@ export type Instance = { thumbnail: string | null; urls: URLs; stats: Stats; - languages: Array; + languages: string[]; registrations: boolean; approval_required: boolean; invites_enabled: boolean; @@ -23,7 +23,7 @@ export type Instance = { characters_reserved_per_url: number; }; media_attachments: { - supported_mime_types: Array; + supported_mime_types: string[]; image_size_limit: number; image_matrix_limit: number; video_size_limit: number; @@ -38,10 +38,10 @@ export type Instance = { }; }; contact_account: Account; - rules: Array; -}; + rules: InstanceRule[]; +} -export type InstanceRule = { +export interface InstanceRule { id: string; text: string; -}; +} diff --git a/types/entities/list.ts b/types/entities/list.ts index b3119da1..d61ccb53 100644 --- a/types/entities/list.ts +++ b/types/entities/list.ts @@ -1,7 +1,7 @@ -export type List = { +export interface List { id: string; title: string; replies_policy: RepliesPolicy; -}; +} export type RepliesPolicy = "followed" | "list" | "none"; diff --git a/types/entities/marker.ts b/types/entities/marker.ts index 01c4118f..8668487c 100644 --- a/types/entities/marker.ts +++ b/types/entities/marker.ts @@ -1,4 +1,4 @@ -export type Marker = { +export interface Marker { home: { last_read_id: string; version: number; @@ -9,4 +9,4 @@ export type Marker = { version: number; updated_at: string; }; -}; +} diff --git a/types/entities/mention.ts b/types/entities/mention.ts index 496e6d0d..b323e149 100644 --- a/types/entities/mention.ts +++ b/types/entities/mention.ts @@ -1,6 +1,6 @@ -export type Mention = { +export interface Mention { id: string; username: string; url: string; acct: string; -}; +} diff --git a/types/entities/notification.ts b/types/entities/notification.ts index 860acd24..cca7fbba 100644 --- a/types/entities/notification.ts +++ b/types/entities/notification.ts @@ -1,14 +1,12 @@ -import { Account } from "./account" -import { Status } from "./status" +import { Account } from "./account"; +import { Status } from "./status"; -namespace MastodonEntity { - export type Notification = { - account: Account - created_at: string - id: string - status?: Status - type: NotificationType - } - - export type NotificationType = string +export interface Notification { + account: Account; + created_at: string; + id: string; + status?: Status; + type: NotificationType; } + +export type NotificationType = string; diff --git a/types/entities/poll.ts b/types/entities/poll.ts index 29e5f6e0..efa3e357 100644 --- a/types/entities/poll.ts +++ b/types/entities/poll.ts @@ -1,11 +1,11 @@ import { PollOption } from "./poll_option"; -export type Poll = { +export interface Poll { id: string; expires_at: string | null; expired: boolean; multiple: boolean; votes_count: number; - options: Array; + options: PollOption[]; voted: boolean; -}; +} diff --git a/types/entities/poll_option.ts b/types/entities/poll_option.ts index 36230998..89375a56 100644 --- a/types/entities/poll_option.ts +++ b/types/entities/poll_option.ts @@ -1,4 +1,4 @@ -export type PollOption = { +export interface PollOption { title: string; votes_count: number | null; -}; +} diff --git a/types/entities/preferences.ts b/types/entities/preferences.ts index 44b1f0a1..eb144ab6 100644 --- a/types/entities/preferences.ts +++ b/types/entities/preferences.ts @@ -1,7 +1,7 @@ -export type Preferences = { +export interface Preferences { "posting:default:visibility": "public" | "unlisted" | "private" | "direct"; "posting:default:sensitive": boolean; "posting:default:language": string | null; "reading:expand:media": "default" | "show_all" | "hide_all"; "reading:expand:spoilers": boolean; -}; +} diff --git a/types/entities/push_subscription.ts b/types/entities/push_subscription.ts index e5df43c3..907a996e 100644 --- a/types/entities/push_subscription.ts +++ b/types/entities/push_subscription.ts @@ -1,14 +1,14 @@ -export type Alerts = { +export interface Alerts { follow: boolean; favourite: boolean; mention: boolean; reblog: boolean; poll: boolean; -}; +} -export type PushSubscription = { +export interface PushSubscription { id: string; endpoint: string; server_key: string; alerts: Alerts; -}; +} diff --git a/types/entities/relationship.ts b/types/entities/relationship.ts index bcc6cf99..330a7f17 100644 --- a/types/entities/relationship.ts +++ b/types/entities/relationship.ts @@ -1,4 +1,4 @@ -export type Relationship = { +export interface Relationship { id: string; following: boolean; followed_by: boolean; @@ -12,5 +12,5 @@ export type Relationship = { endorsed: boolean; notifying: boolean; note: string; - languages: Array; -}; + languages: string[]; +} diff --git a/types/entities/report.ts b/types/entities/report.ts index e1ef7641..487fd7b0 100644 --- a/types/entities/report.ts +++ b/types/entities/report.ts @@ -1,15 +1,15 @@ import { Account } from "./account"; -export type Report = { +export interface Report { id: string; action_taken: boolean; action_taken_at: string | null; category: Category; comment: string; forwarded: boolean; - status_ids: Array | null; - rule_ids: Array | null; + status_ids: string[] | null; + rule_ids: string[] | null; target_account: Account; -}; +} export type Category = "spam" | "violation" | "other"; diff --git a/types/entities/results.ts b/types/entities/results.ts index 42cd4c09..ba10872d 100644 --- a/types/entities/results.ts +++ b/types/entities/results.ts @@ -2,8 +2,8 @@ import { Account } from "./account"; import { Status } from "./status"; import { Tag } from "./tag"; -export type Results = { - accounts: Array; - statuses: Array; - hashtags: Array; -}; +export interface Results { + accounts: Account[]; + statuses: Status[]; + hashtags: Tag[]; +} diff --git a/types/entities/role.ts b/types/entities/role.ts index 85251115..4566feac 100644 --- a/types/entities/role.ts +++ b/types/entities/role.ts @@ -1,3 +1,3 @@ -export type Role = { +export interface Role { name: string; -}; +} diff --git a/types/entities/scheduled_status.ts b/types/entities/scheduled_status.ts index 1e4d9b7b..58330967 100644 --- a/types/entities/scheduled_status.ts +++ b/types/entities/scheduled_status.ts @@ -1,9 +1,9 @@ import { Attachment } from "./attachment"; import { StatusParams } from "./status_params"; -export type ScheduledStatus = { +export interface ScheduledStatus { id: string; scheduled_at: string; params: StatusParams; - media_attachments: Array; -}; + media_attachments: Attachment[]; +} diff --git a/types/entities/source.ts b/types/entities/source.ts index e8352d65..b11c0b33 100644 --- a/types/entities/source.ts +++ b/types/entities/source.ts @@ -1,9 +1,9 @@ import { Field } from "./field"; -export type Source = { +export interface Source { privacy: string | null; sensitive: boolean | null; language: string | null; note: string; - fields: Array; -}; + fields: Field[]; +} diff --git a/types/entities/stats.ts b/types/entities/stats.ts index 3baf0639..4f3e825d 100644 --- a/types/entities/stats.ts +++ b/types/entities/stats.ts @@ -1,5 +1,5 @@ -export type Stats = { +export interface Stats { user_count: number; status_count: number; domain_count: number; -}; +} diff --git a/types/entities/status.ts b/types/entities/status.ts index 6c1e60d8..4a0eb2a9 100644 --- a/types/entities/status.ts +++ b/types/entities/status.ts @@ -6,7 +6,7 @@ import { Emoji } from "./emoji"; import { Mention } from "./mention"; import { Poll } from "./poll"; -export type Status = { +export interface Status { id: string; uri: string; url: string; @@ -26,9 +26,9 @@ export type Status = { sensitive: boolean; spoiler_text: string; visibility: "public" | "unlisted" | "private" | "direct"; - media_attachments: Array; - mentions: Array; - tags: Array; + media_attachments: Attachment[]; + mentions: Mention[]; + tags: StatusTag[]; card: Card | null; poll: Poll | null; application: Application | null; @@ -38,9 +38,9 @@ export type Status = { // These parameters are unique parameters in fedibird.com for quote. quote_id?: string; quote?: Status | null; -}; +} -export type StatusTag = { +export interface StatusTag { name: string; url: string; -}; +} diff --git a/types/entities/status_params.ts b/types/entities/status_params.ts index 5b638efe..3f67a6c0 100644 --- a/types/entities/status_params.ts +++ b/types/entities/status_params.ts @@ -1,10 +1,10 @@ -export type StatusParams = { +export interface StatusParams { text: string; in_reply_to_id: string | null; - media_ids: Array | null; + media_ids: string[] | null; sensitive: boolean | null; spoiler_text: string | null; visibility: "public" | "unlisted" | "private" | "direct" | null; scheduled_at: string | null; application_id: number; -}; +} diff --git a/types/entities/status_source.ts b/types/entities/status_source.ts index 82fea66d..095d4682 100644 --- a/types/entities/status_source.ts +++ b/types/entities/status_source.ts @@ -1,5 +1,5 @@ -export type StatusSource = { +export interface StatusSource { id: string; text: string; spoiler_text: string; -}; +} diff --git a/types/entities/tag.ts b/types/entities/tag.ts index 59db622f..7022eccb 100644 --- a/types/entities/tag.ts +++ b/types/entities/tag.ts @@ -1,8 +1,8 @@ import { History } from "./history"; -export type Tag = { +export interface Tag { name: string; url: string; - history: Array; + history: History[]; following?: boolean; -}; +} diff --git a/types/entities/token.ts b/types/entities/token.ts index cbe9e0a0..90b94280 100644 --- a/types/entities/token.ts +++ b/types/entities/token.ts @@ -1,6 +1,6 @@ -export type Token = { +export interface Token { access_token: string; token_type: string; scope: string; created_at: number; -}; +} diff --git a/types/entities/urls.ts b/types/entities/urls.ts index 3c28faea..1f877fe2 100644 --- a/types/entities/urls.ts +++ b/types/entities/urls.ts @@ -1,3 +1,3 @@ -export type URLs = { +export interface URLs { streaming_api: string; -}; +} diff --git a/utils/config.ts b/utils/config.ts index f8f13eac..d5f4c076 100644 --- a/utils/config.ts +++ b/utils/config.ts @@ -1,6 +1,6 @@ import data from "../config/config.toml"; -export type ConfigType = { +export interface ConfigType { database: { host: string; port: number; @@ -8,7 +8,7 @@ export type ConfigType = { password: string; database: string; } - [ key: string ]: any; + [ key: string ]: unknown; } export const getConfig = () => { diff --git a/utils/response.ts b/utils/response.ts index 1a961acf..eb820d94 100644 --- a/utils/response.ts +++ b/utils/response.ts @@ -1,4 +1,4 @@ -export const jsonResponse = (data: object, status: number = 200) => { +export const jsonResponse = (data: object, status = 200) => { return new Response(JSON.stringify(data), { headers: { "Content-Type": "application/json"