🎉 Initial Commit(Migrated from Interactive)

This commit is contained in:
2024-03-27 23:07:18 +08:00
commit 3a1cf006f4
126 changed files with 4471 additions and 0 deletions

29
src/stores/editor.ts Normal file
View File

@@ -0,0 +1,29 @@
import { defineStore } from "pinia"
import { reactive, ref } from "vue"
export const useEditor = defineStore("editor", () => {
const done = ref(false)
const show = reactive({
moment: false,
article: false,
comment: false,
delete: false
})
const related = reactive<{
edit_to: any
comment_to: any
reply_to: any
repost_to: any
delete_to: any
}>({
edit_to: null,
comment_to: null,
reply_to: null,
repost_to: null,
delete_to: null
})
return { show, related, done }
})

37
src/stores/realms.ts Normal file
View File

@@ -0,0 +1,37 @@
import { reactive, ref } from "vue"
import { defineStore } from "pinia"
import { checkLoggedIn, getAtk } from "@/stores/userinfo"
import { request } from "@/scripts/request"
export const useRealms = defineStore("realms", () => {
const done = ref(false)
const show = reactive({
editor: false,
delete: false
})
const related_to = reactive<{ edit_to: any; delete_to: any }>({
edit_to: null,
delete_to: null
})
const available = ref<any[]>([])
async function list() {
if (!checkLoggedIn()) return
const res = await request("interactive", "/api/realms/me/available", {
headers: { Authorization: `Bearer ${getAtk()}` }
})
if (res.status !== 200) {
throw new Error(await res.text())
} else {
available.value = await res.json()
}
}
list().then(() => console.log("[STARTUP HOOK] Fetch available realm successes."))
return { done, show, related: related_to, available, list }
})

56
src/stores/userinfo.ts Normal file
View File

@@ -0,0 +1,56 @@
import Cookie from "universal-cookie"
import { defineStore } from "pinia"
import { ref } from "vue"
import { request } from "@/scripts/request"
export interface Userinfo {
isReady: boolean
isLoggedIn: boolean
displayName: string
data: any
}
const defaultUserinfo: Userinfo = {
isReady: false,
isLoggedIn: false,
displayName: "Citizen",
data: null
}
export function getAtk(): string {
return new Cookie().get("identity_auth_key")
}
export function checkLoggedIn(): boolean {
return new Cookie().get("identity_auth_key")
}
export const useUserinfo = defineStore("userinfo", () => {
const userinfo = ref(defaultUserinfo)
const isReady = ref(false)
async function readProfiles() {
if (!checkLoggedIn()) {
isReady.value = true
}
const res = await request("interactive", "/api/users/me", {
headers: { Authorization: `Bearer ${getAtk()}` }
})
if (res.status !== 200) {
return
}
const data = await res.json()
userinfo.value = {
isReady: true,
isLoggedIn: true,
displayName: data["nick"],
data: data
}
}
return { userinfo, isReady, readProfiles }
})

14
src/stores/wellKnown.ts Normal file
View File

@@ -0,0 +1,14 @@
import { request } from "@/scripts/request"
import { defineStore } from "pinia"
import { ref } from "vue"
export const useWellKnown = defineStore("well-known", () => {
const wellKnown = ref<any>(null)
async function readWellKnown() {
const res = await request("interactive", "/.well-known")
wellKnown.value = await res.json()
}
return { wellKnown, readWellKnown }
})