From a4fafc180ee243e82c1a26a51090f812443b9531 Mon Sep 17 00:00:00 2001 From: lesion Date: Sun, 8 Sep 2024 23:05:29 +0200 Subject: [PATCH] WIP: keep going rewriting gancio in nuxt3 --- components/Admin/Settings.vue | 18 ++ components/Admin/SetupAlert.vue | 18 ++ components/Core/AppBar.vue | 58 +++++ components/Core/Footer.vue | 42 ++++ components/Core/Img.vue | 97 ++++++++ components/Event.vue | 16 +- components/Event/Detail.vue | 70 ++++++ components/NavBar.vue | 16 ++ components/NavHeader.vue | 87 +++++++ components/NavSearch.vue | 68 ++++++ composables/useAuth.ts | 90 +++++++ composables/useSettings.ts | 19 ++ layouts/default.vue | 10 +- pages/Login.vue | 4 +- pages/about.vue | 8 + pages/admin/index.vue | 26 ++ pages/collection/[name].vue | 22 ++ pages/event/[slug].vue | 350 ++++++++++++++++++++++++++- pages/index.vue | 10 +- pages/place/[place].vue | 92 +++++++ plugins/formatter.ts | 14 ++ plugins/validators.ts | 2 - server/api/ap_users/trusted.get.ts | 5 + server/api/collections/[name].get.ts | 5 + server/api/collections/home.get.ts | 3 + server/api/events/[slug].get.ts | 4 +- server/api/events/index.get.ts | 4 +- server/api/place/[place].ts | 8 + server/api/settings/[key].get.ts | 3 + server/api/settings/index.put.ts | 3 + server/api/settings/index.ts | 3 + server/api/tag/[tag].ts | 6 + server/api/utils/ping.ts | 1 + server/api/utils/reachable.ts | 13 + server/models/ap_user.js | 15 -- server/models/collection.js | 20 -- server/models/event.js | 102 -------- server/models/eventnotification.js | 18 -- server/models/filter.js | 26 -- server/models/index.js | 180 -------------- server/models/instance.js | 12 - server/models/message.js | 27 --- server/models/models.js | 21 -- server/models/notification.js | 22 -- server/models/oauth_client.js | 13 - server/models/oauth_code.js | 10 - server/models/oauth_token.js | 22 -- server/models/place.js | 12 - server/models/resource.js | 10 - server/models/setting.js | 11 - server/models/tag.js | 9 - server/models/user.js | 65 ----- server/routes/headerimage.png.ts | 1 + server/utils/collections.ts | 25 ++ server/utils/events.ts | 24 ++ server/utils/place.ts | 14 ++ server/utils/sequelize.ts | 138 ++++++++++- server/utils/tag.ts | 11 + 58 files changed, 1376 insertions(+), 627 deletions(-) create mode 100644 components/Admin/Settings.vue create mode 100644 components/Admin/SetupAlert.vue create mode 100644 components/Core/AppBar.vue create mode 100644 components/Core/Footer.vue create mode 100644 components/Core/Img.vue create mode 100644 components/Event/Detail.vue create mode 100644 components/NavBar.vue create mode 100644 components/NavHeader.vue create mode 100644 components/NavSearch.vue create mode 100644 composables/useAuth.ts create mode 100644 composables/useSettings.ts create mode 100644 pages/about.vue create mode 100644 pages/admin/index.vue create mode 100644 pages/collection/[name].vue create mode 100644 pages/place/[place].vue create mode 100644 plugins/formatter.ts create mode 100644 server/api/ap_users/trusted.get.ts create mode 100644 server/api/collections/[name].get.ts create mode 100644 server/api/collections/home.get.ts create mode 100644 server/api/place/[place].ts create mode 100644 server/api/settings/[key].get.ts create mode 100644 server/api/settings/index.put.ts create mode 100644 server/api/settings/index.ts create mode 100644 server/api/tag/[tag].ts create mode 100644 server/api/utils/ping.ts create mode 100644 server/api/utils/reachable.ts delete mode 100644 server/models/ap_user.js delete mode 100644 server/models/collection.js delete mode 100644 server/models/event.js delete mode 100644 server/models/eventnotification.js delete mode 100644 server/models/filter.js delete mode 100644 server/models/index.js delete mode 100644 server/models/instance.js delete mode 100644 server/models/message.js delete mode 100644 server/models/models.js delete mode 100644 server/models/notification.js delete mode 100644 server/models/oauth_client.js delete mode 100644 server/models/oauth_code.js delete mode 100644 server/models/oauth_token.js delete mode 100644 server/models/place.js delete mode 100644 server/models/resource.js delete mode 100644 server/models/setting.js delete mode 100644 server/models/tag.js delete mode 100644 server/models/user.js create mode 100644 server/routes/headerimage.png.ts create mode 100644 server/utils/collections.ts create mode 100644 server/utils/events.ts create mode 100644 server/utils/place.ts create mode 100644 server/utils/tag.ts diff --git a/components/Admin/Settings.vue b/components/Admin/Settings.vue new file mode 100644 index 00000000..1cb9cbcc --- /dev/null +++ b/components/Admin/Settings.vue @@ -0,0 +1,18 @@ + + \ No newline at end of file diff --git a/components/Admin/SetupAlert.vue b/components/Admin/SetupAlert.vue new file mode 100644 index 00000000..81370083 --- /dev/null +++ b/components/Admin/SetupAlert.vue @@ -0,0 +1,18 @@ + + \ No newline at end of file diff --git a/components/Core/AppBar.vue b/components/Core/AppBar.vue new file mode 100644 index 00000000..48e7481c --- /dev/null +++ b/components/Core/AppBar.vue @@ -0,0 +1,58 @@ + + + + + \ No newline at end of file diff --git a/components/Core/Footer.vue b/components/Core/Footer.vue new file mode 100644 index 00000000..b19b0c33 --- /dev/null +++ b/components/Core/Footer.vue @@ -0,0 +1,42 @@ + + \ No newline at end of file diff --git a/components/Core/Img.vue b/components/Core/Img.vue new file mode 100644 index 00000000..14d6be29 --- /dev/null +++ b/components/Core/Img.vue @@ -0,0 +1,97 @@ + + + \ No newline at end of file diff --git a/components/Event.vue b/components/Event.vue index a72019a0..529c274b 100644 --- a/components/Event.vue +++ b/components/Event.vue @@ -1,15 +1,17 @@ + diff --git a/components/NavBar.vue b/components/NavBar.vue new file mode 100644 index 00000000..e69a883f --- /dev/null +++ b/components/NavBar.vue @@ -0,0 +1,16 @@ + + diff --git a/components/NavHeader.vue b/components/NavHeader.vue new file mode 100644 index 00000000..769d52a9 --- /dev/null +++ b/components/NavHeader.vue @@ -0,0 +1,87 @@ + + \ No newline at end of file diff --git a/components/NavSearch.vue b/components/NavSearch.vue new file mode 100644 index 00000000..1e28ea9f --- /dev/null +++ b/components/NavSearch.vue @@ -0,0 +1,68 @@ + + + + + \ No newline at end of file diff --git a/composables/useAuth.ts b/composables/useAuth.ts new file mode 100644 index 00000000..e1ab132a --- /dev/null +++ b/composables/useAuth.ts @@ -0,0 +1,90 @@ +import type { User } from "#build/types/nitro-imports" + +export default () => { + const authUser = useState('auth_user', () => null) + const authLoading = useState('auth_loading', () => true) + + const isLogged = computed(() => !!authUser.value?.id ) + + const isAdmin = computed(() => !!(authUser.value?.role === 'admin')) + + async function login (username: string, password: string) { + authLoading.value = true + + try { + + const data = await $fetch('/api/auth/login', { + method: 'POST', + body: { + username, + password + } + }) + + authUser.value = data + + } finally { + authLoading.value = false + } + } + + + async function refreshToken () { + try { + await $fetch('/api/auth/refresh') + } catch (e) { + console.error('Error', e) + authUser.value = null + } + } + + async function getUser (token: string) { + const data = await $fetch('/api/auth/user', { headers: { + cookie: `access_token=${token};` + } }).catch() + authUser.value = data + } + + // const reRefreshAccessToken = () => { + // const authToken = useAuthToken() + + // if (!authToken.value) { + // return + // } + + // const jwt = jwt_decode(authToken.value) + + // const newRefreshTime = jwt.exp - 60000 + + // setTimeout(async () => { + // await refreshToken() + // reRefreshAccessToken() + // }, newRefreshTime); + // } + + async function initAuth () { + authLoading.value = true + try { + await refreshToken() + // await getUser() + } finally { + authLoading.value = false + } + } + + async function logout () { + await $fetch('/api/auth/logout', { method: 'POST' }) + authUser.value = null + } + + return { + login, + logout, + authUser, + getUser, + authLoading, + isLogged, + isAdmin, + initAuth + } + } \ No newline at end of file diff --git a/composables/useSettings.ts b/composables/useSettings.ts new file mode 100644 index 00000000..95ce870c --- /dev/null +++ b/composables/useSettings.ts @@ -0,0 +1,19 @@ +export default () => { + type SettingsType = + | { [key: string]: string } + + // const { data: Settings } = await useFetch('/api/setting') + const Settings = useState('settings', () => reactive({ })) + + const loadSettings = async () => { + Settings.value = await $fetch('/api/settings') + } + + const saveSetting = async (key: string, value: string) => { + Settings.value[key] = value + await $fetch(`/api/setting`, { method: 'POST', body: { key, value } }) + } + + return { Settings, saveSetting, loadSettings } + } + \ No newline at end of file diff --git a/layouts/default.vue b/layouts/default.vue index c22799bb..e6e6c170 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -8,16 +8,16 @@ const config = useRuntimeConfig() diff --git a/pages/Login.vue b/pages/Login.vue index 6b2b85c7..9ede2ae6 100644 --- a/pages/Login.vue +++ b/pages/Login.vue @@ -41,8 +41,8 @@ - + \ No newline at end of file diff --git a/pages/admin/index.vue b/pages/admin/index.vue new file mode 100644 index 00000000..d3bb9263 --- /dev/null +++ b/pages/admin/index.vue @@ -0,0 +1,26 @@ + + \ No newline at end of file diff --git a/pages/collection/[name].vue b/pages/collection/[name].vue new file mode 100644 index 00000000..66a317f0 --- /dev/null +++ b/pages/collection/[name].vue @@ -0,0 +1,22 @@ + + \ No newline at end of file diff --git a/pages/event/[slug].vue b/pages/event/[slug].vue index 4b2c20a3..69b93555 100644 --- a/pages/event/[slug].vue +++ b/pages/event/[slug].vue @@ -1,5 +1,5 @@ \ No newline at end of file + + + + + \ No newline at end of file diff --git a/pages/index.vue b/pages/index.vue index cc868342..def822d8 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -4,8 +4,8 @@