From 90c45b435fed36c5a7595378d4c2fd86a6e67431 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 14 Nov 2022 10:20:07 +0800 Subject: [PATCH] feat: use masto client --- .vscode/settings.json | 1 + api-client/index.ts | 24 ---- api-client/types.ts | 114 ------------------ components/AccountInfo.vue | 14 ++- components/PostBody.vue | 29 ----- components/PostCard.vue | 15 --- .../StatusActions.vue} | 12 +- components/status/StatusBody.vue | 31 +++++ components/status/StatusCard.vue | 22 ++++ composables/client.ts | 10 +- pages/{[user] => @[user]}/[post].vue | 0 pages/@[user]/index.vue | 13 ++ pages/index.vue | 8 +- plugins/masto.ts | 8 ++ 14 files changed, 96 insertions(+), 205 deletions(-) delete mode 100644 api-client/index.ts delete mode 100644 api-client/types.ts delete mode 100644 components/PostBody.vue delete mode 100644 components/PostCard.vue rename components/{PostActions.vue => status/StatusActions.vue} (74%) create mode 100644 components/status/StatusBody.vue create mode 100644 components/status/StatusCard.vue rename pages/{[user] => @[user]}/[post].vue (100%) create mode 100644 pages/@[user]/index.vue create mode 100644 plugins/masto.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index a35db91d..6d6475d4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ }, "editor.formatOnSave": false, "cSpell.words": [ + "masto", "Nuxtodon" ] } diff --git a/api-client/index.ts b/api-client/index.ts deleted file mode 100644 index 740d4c83..00000000 --- a/api-client/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Headers, createFetch, fetch } from 'ohmyfetch' -import type { Post } from './types' - -export interface MastodonClientOptions { - host: string -} - -export class Client { - $fetch: ReturnType = undefined! - - constructor(public options: MastodonClientOptions) { - this.$fetch = createFetch({ - defaults: { - baseURL: options.host, - }, - fetch, - Headers, - }) - } - - getPublicTimeline(): Promise { - return this.$fetch('/api/v1/timelines/public') - } -} diff --git a/api-client/types.ts b/api-client/types.ts deleted file mode 100644 index bf0faae5..00000000 --- a/api-client/types.ts +++ /dev/null @@ -1,114 +0,0 @@ -export interface Post { - id: string - created_at: Date - in_reply_to_id: null | string - in_reply_to_account_id: null | string - sensitive: boolean - spoiler_text: string - visibility: Visibility - language: string - uri: string - url: string - replies_count: number - reblogs_count: number - favourites_count: number - edited_at: null - favourited: boolean - reblogged: boolean - muted: boolean - bookmarked: boolean - content: string - filtered: any[] - reblog: null - account: Account - media_attachments: MediaAttachment[] - mentions: any[] - tags: Tag[] - emojis: Emoji[] - card: null - poll: null - application?: Application -} - -export interface Account { - id: string - username: string - acct: string - display_name: string - locked: boolean - bot: boolean - discoverable: boolean - group: boolean - created_at: Date - note: string - url: string - avatar: string - avatar_static: string - header: string - header_static: string - followers_count: number - following_count: number - statuses_count: number - last_status_at: Date - emojis: Emoji[] - fields: Field[] - noindex?: boolean -} - -export interface Emoji { - shortcode: string - url: string - static_url: string - visible_in_picker: boolean -} - -export interface Field { - name: string - value: string - verified_at: Date | null -} - -export interface Application { - name: string - website: null | string -} - -export interface MediaAttachment { - id: string - type: string - url: string - preview_url: string - remote_url: string - preview_remote_url: null - text_url: null - meta: Meta - description: null | string - blurhash: string -} - -export interface Meta { - focus?: Focus - original: Original - small: Original -} - -export interface Focus { - x: number - y: number -} - -export interface Original { - width: number - height: number - size: string - aspect: number -} - -export interface Tag { - name: string - url: string -} - -export enum Visibility { - Public = 'public', -} diff --git a/components/AccountInfo.vue b/components/AccountInfo.vue index a2710f60..50a69d45 100644 --- a/components/AccountInfo.vue +++ b/components/AccountInfo.vue @@ -1,7 +1,7 @@ @@ -9,15 +9,17 @@ const props = defineProps<{ diff --git a/components/PostBody.vue b/components/PostBody.vue deleted file mode 100644 index d9c8a6cb..00000000 --- a/components/PostBody.vue +++ /dev/null @@ -1,29 +0,0 @@ - - - - - diff --git a/components/PostCard.vue b/components/PostCard.vue deleted file mode 100644 index 2df71417..00000000 --- a/components/PostCard.vue +++ /dev/null @@ -1,15 +0,0 @@ - - - diff --git a/components/PostActions.vue b/components/status/StatusActions.vue similarity index 74% rename from components/PostActions.vue rename to components/status/StatusActions.vue index 26e7d60c..6c5590f0 100644 --- a/components/PostActions.vue +++ b/components/status/StatusActions.vue @@ -1,8 +1,8 @@ @@ -10,15 +10,15 @@ const props = defineProps<{