From 58f55fa9fcf1c88a316cdac2d6f4fd3ea43900cd Mon Sep 17 00:00:00 2001 From: Ravinou Date: Sat, 19 Apr 2025 21:30:59 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=9A=A1=20update=20new=20api=20ur?= =?UTF-8?q?l=20to=20components?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StorageUsedChartBar/StorageUsedChartBar.tsx | 2 +- Containers/RepoList/RepoList.tsx | 8 ++++---- Containers/RepoManage/RepoManage.tsx | 8 ++++---- Containers/SetupWizard/SetupWizard.tsx | 4 ++-- .../AppriseAlertSettings/AppriseAlertSettings.tsx | 6 +++--- .../AppriseAlertSettings/AppriseMode/AppriseMode.tsx | 4 ++-- .../AppriseAlertSettings/AppriseURLs/AppriseURLs.tsx | 4 ++-- .../EmailAlertSettings/EmailAlertSettings.tsx | 6 +++--- Containers/UserSettings/EmailSettings/EmailSettings.tsx | 2 +- Containers/UserSettings/Integrations/Integrations.tsx | 6 +++--- .../UserSettings/PasswordSettings/PasswordSettings.tsx | 2 +- Containers/UserSettings/UserSettings.tsx | 2 +- .../UserSettings/UsernameSettings/UsernameSettings.tsx | 2 +- pages/api/v1/notif/apprise/{send-test.ts => test.ts} | 0 .../v1/notif/email/{send-test.test.ts => test.test.ts} | 2 +- pages/api/v1/notif/email/{send-test.ts => test.ts} | 0 pages/index.tsx | 2 +- 17 files changed, 30 insertions(+), 30 deletions(-) rename pages/api/v1/notif/apprise/{send-test.ts => test.ts} (100%) rename pages/api/v1/notif/email/{send-test.test.ts => test.test.ts} (95%) rename pages/api/v1/notif/email/{send-test.ts => test.ts} (100%) diff --git a/Containers/Monitoring/StorageUsedChartBar/StorageUsedChartBar.tsx b/Containers/Monitoring/StorageUsedChartBar/StorageUsedChartBar.tsx index 5696155..3a9bd86 100644 --- a/Containers/Monitoring/StorageUsedChartBar/StorageUsedChartBar.tsx +++ b/Containers/Monitoring/StorageUsedChartBar/StorageUsedChartBar.tsx @@ -17,7 +17,7 @@ export default function StorageUsedChartBar() { useEffect(() => { const dataFetch = async () => { try { - const response = await fetch('/api/repo', { + const response = await fetch('/api/v1/repositories', { method: 'GET', headers: { 'Content-type': 'application/json', diff --git a/Containers/RepoList/RepoList.tsx b/Containers/RepoList/RepoList.tsx index 27eed52..ba00f05 100644 --- a/Containers/RepoList/RepoList.tsx +++ b/Containers/RepoList/RepoList.tsx @@ -30,7 +30,7 @@ export default function RepoList() { ////Datas //Write a fetcher function to wrap the native fetch function and return the result of a call to url in json format const fetcher = async (url: string) => await fetch(url).then((res) => res.json()); - const { data, error } = useSWR('/api/repo', fetcher); + const { data, error } = useSWR('/api/v1/repositories', fetcher); ////LifeCycle //Component did mount @@ -46,7 +46,7 @@ export default function RepoList() { //Fetch wizardEnv to hydrate Repo components const fetchWizardEnv = async () => { try { - const response = await fetch('/api/account/getWizardEnv', { + const response = await fetch('/api/v1/account/wizard-env', { method: 'GET', headers: { 'Content-type': 'application/json', @@ -70,8 +70,8 @@ export default function RepoList() { //Firstly, check the availability of data and condition it. if (!data) { - //Force mutate after login (force a API GET on /api/repo to load repoList) - mutate('/api/repo'); + //Force mutate after login (force a API GET on /api/v1/repositories to load repoList) + mutate('/api/v1/repositories'); return ; } if (error) { diff --git a/Containers/RepoManage/RepoManage.tsx b/Containers/RepoManage/RepoManage.tsx index 66cb31e..cf17425 100644 --- a/Containers/RepoManage/RepoManage.tsx +++ b/Containers/RepoManage/RepoManage.tsx @@ -67,7 +67,7 @@ export default function RepoManage(props: RepoManageProps) { //Delete a repo const deleteHandler = async () => { //API Call for delete - await fetch('/api/repo/id/' + router.query.slug + '/delete', { + await fetch('/api/v1/repositories/' + router.query.slug, { method: 'DELETE', headers: { 'Content-type': 'application/json', @@ -106,7 +106,7 @@ export default function RepoManage(props: RepoManageProps) { // Extract the first two columns of the SSH key in the form const publicKeyPrefix = sshPublicKey.split(' ').slice(0, 2).join(' '); - const response = await fetch('/api/repo', { method: 'GET' }); + const response = await fetch('/api/v1/repositories', { method: 'GET' }); const data = await response.json(); const conflictingRepo = data.repoList.find((repo: { sshPublicKey: string; id: number }) => { @@ -153,7 +153,7 @@ export default function RepoManage(props: RepoManageProps) { appendOnlyMode: dataForm.appendOnlyMode, }; //POST API to send new repo - await fetch('/api/repo/add', { + await fetch('/api/v1/repositories', { method: 'POST', headers: { 'Content-type': 'application/json', @@ -187,7 +187,7 @@ export default function RepoManage(props: RepoManageProps) { lanCommand: dataForm.lanCommand, appendOnlyMode: dataForm.appendOnlyMode, }; - await fetch('/api/repo/id/' + router.query.slug + '/edit', { + await fetch('/api/v1/repositories/' + router.query.slug, { method: 'PATCH', headers: { 'Content-type': 'application/json', diff --git a/Containers/SetupWizard/SetupWizard.tsx b/Containers/SetupWizard/SetupWizard.tsx index 9f595f5..4a48745 100644 --- a/Containers/SetupWizard/SetupWizard.tsx +++ b/Containers/SetupWizard/SetupWizard.tsx @@ -30,7 +30,7 @@ function SetupWizard(props: SetupWizardProps) { //retrieve the repository list const fetchRepoList = async () => { try { - const response = await fetch('/api/repo', { + const response = await fetch('/api/v1/repositories', { method: 'GET', headers: { 'Content-type': 'application/json', @@ -46,7 +46,7 @@ function SetupWizard(props: SetupWizardProps) { //Fetch wizardEnv to hydrate Wizard' steps const fetchWizardEnv = async () => { try { - const response = await fetch('/api/account/getWizardEnv', { + const response = await fetch('/api/v1/account/wizard-env', { method: 'GET', headers: { 'Content-type': 'application/json', diff --git a/Containers/UserSettings/AppriseAlertSettings/AppriseAlertSettings.tsx b/Containers/UserSettings/AppriseAlertSettings/AppriseAlertSettings.tsx index 456de3c..9b190f4 100644 --- a/Containers/UserSettings/AppriseAlertSettings/AppriseAlertSettings.tsx +++ b/Containers/UserSettings/AppriseAlertSettings/AppriseAlertSettings.tsx @@ -43,7 +43,7 @@ export default function AppriseAlertSettings() { //Initial fetch to get the status of Apprise Alert const getAppriseAlert = async () => { try { - const response = await fetch('/api/account/getAppriseAlert', { + const response = await fetch('/api/v1/notif/apprise/alert', { method: 'GET', headers: { 'Content-type': 'application/json', @@ -67,7 +67,7 @@ export default function AppriseAlertSettings() { const onChangeSwitchHandler = async (data: AppriseAlertDataForm) => { clearError(); setIsSwitchDisabled(true); - await fetch('/api/account/updateAppriseAlert', { + await fetch('/api/v1/notif/apprise/alert', { method: 'PUT', headers: { 'Content-type': 'application/json', @@ -98,7 +98,7 @@ export default function AppriseAlertSettings() { clearError(); setIsSendingTestNotification(true); try { - const response = await fetch('/api/account/sendTestApprise', { + const response = await fetch('/api/v1/notif/apprise/test', { method: 'POST', }); const result = await response.json(); diff --git a/Containers/UserSettings/AppriseAlertSettings/AppriseMode/AppriseMode.tsx b/Containers/UserSettings/AppriseAlertSettings/AppriseMode/AppriseMode.tsx index 0632b8a..b36a92d 100644 --- a/Containers/UserSettings/AppriseAlertSettings/AppriseMode/AppriseMode.tsx +++ b/Containers/UserSettings/AppriseAlertSettings/AppriseMode/AppriseMode.tsx @@ -35,7 +35,7 @@ export default function AppriseMode() { //Initial fetch to get Apprise Mode enabled const getAppriseMode = async () => { try { - const response = await fetch('/api/account/getAppriseMode', { + const response = await fetch('/api/v1/notif/apprise/mode', { method: 'GET', headers: { 'Content-type': 'application/json', @@ -63,7 +63,7 @@ export default function AppriseMode() { setIsLoading(true); try { - const response = await fetch('/api/account/updateAppriseMode', { + const response = await fetch('/api/v1/notif/apprise/mode', { method: 'PUT', headers: { 'Content-type': 'application/json', diff --git a/Containers/UserSettings/AppriseAlertSettings/AppriseURLs/AppriseURLs.tsx b/Containers/UserSettings/AppriseAlertSettings/AppriseURLs/AppriseURLs.tsx index 42510be..489d9da 100644 --- a/Containers/UserSettings/AppriseAlertSettings/AppriseURLs/AppriseURLs.tsx +++ b/Containers/UserSettings/AppriseAlertSettings/AppriseURLs/AppriseURLs.tsx @@ -31,7 +31,7 @@ export default function AppriseURLs() { //Initial fetch to build the list of Apprise Services enabled const getAppriseServices = async () => { try { - const response = await fetch('/api/account/getAppriseServices', { + const response = await fetch('/api/v1/notif/apprise/services', { method: 'GET', headers: { 'Content-type': 'application/json', @@ -60,7 +60,7 @@ export default function AppriseURLs() { setIsLoading(true); try { - const response = await fetch('/api/account/updateAppriseServices', { + const response = await fetch('/api/v1/notif/apprise/services', { method: 'PUT', headers: { 'Content-type': 'application/json', diff --git a/Containers/UserSettings/EmailAlertSettings/EmailAlertSettings.tsx b/Containers/UserSettings/EmailAlertSettings/EmailAlertSettings.tsx index cc0a698..0609b24 100644 --- a/Containers/UserSettings/EmailAlertSettings/EmailAlertSettings.tsx +++ b/Containers/UserSettings/EmailAlertSettings/EmailAlertSettings.tsx @@ -38,7 +38,7 @@ export default function EmailAlertSettings() { useEffect(() => { const dataFetch = async () => { try { - const response = await fetch('/api/account/getEmailAlert', { + const response = await fetch('/api/v1/notif/email/alert', { method: 'GET', headers: { 'Content-type': 'application/json', @@ -62,7 +62,7 @@ export default function EmailAlertSettings() { const onChangeSwitchHandler = async (data: EmailAlertDTO) => { clearError(); setIsSwitchDisabled(true); - await fetch('/api/account/updateEmailAlert', { + await fetch('/api/v1/notif/email/alert', { method: 'PUT', headers: { 'Content-type': 'application/json', @@ -93,7 +93,7 @@ export default function EmailAlertSettings() { clearError(); setIsSendingTestNotification(true); try { - const response = await fetch('/api/account/sendTestEmail', { + const response = await fetch('/api/v1/notif/email/test', { method: 'POST', headers: { 'Content-type': 'application/json', diff --git a/Containers/UserSettings/EmailSettings/EmailSettings.tsx b/Containers/UserSettings/EmailSettings/EmailSettings.tsx index fb2af09..01b8bed 100644 --- a/Containers/UserSettings/EmailSettings/EmailSettings.tsx +++ b/Containers/UserSettings/EmailSettings/EmailSettings.tsx @@ -40,7 +40,7 @@ export default function EmailSettings(props: EmailSettingDTO) { setIsLoading(true); try { - const response = await fetch('/api/account/updateEmail', { + const response = await fetch('/api/v1/account/email', { method: 'PUT', headers: { 'Content-type': 'application/json', diff --git a/Containers/UserSettings/Integrations/Integrations.tsx b/Containers/UserSettings/Integrations/Integrations.tsx index 7acc66c..650baba 100644 --- a/Containers/UserSettings/Integrations/Integrations.tsx +++ b/Containers/UserSettings/Integrations/Integrations.tsx @@ -64,7 +64,7 @@ export default function Integrations() { const fetchTokenList = async () => { try { - const response = await fetch('/api/account/tokenManager', { + const response = await fetch('/api/v1/integration/token-manager', { method: 'GET', headers: { 'Content-type': 'application/json', @@ -109,7 +109,7 @@ export default function Integrations() { // Post API to send the new token integration try { - const response = await fetch('/api/account/tokenManager', { + const response = await fetch('/api/v1/integration/token-manager', { method: 'POST', headers: { 'Content-type': 'application/json', @@ -146,7 +146,7 @@ export default function Integrations() { const deleteTokenHandler = async (tokenName: string) => { setIsDeleteLoading(true); try { - const response = await fetch('/api/account/tokenManager', { + const response = await fetch('/api/v1/integration/token-manager', { method: 'DELETE', headers: { 'Content-type': 'application/json', diff --git a/Containers/UserSettings/PasswordSettings/PasswordSettings.tsx b/Containers/UserSettings/PasswordSettings/PasswordSettings.tsx index 0068452..3723339 100644 --- a/Containers/UserSettings/PasswordSettings/PasswordSettings.tsx +++ b/Containers/UserSettings/PasswordSettings/PasswordSettings.tsx @@ -35,7 +35,7 @@ export default function PasswordSettings() { setIsLoading(true); try { - const response = await fetch('/api/account/updatePassword', { + const response = await fetch('/api/v1/account/password', { method: 'PUT', headers: { 'Content-type': 'application/json', diff --git a/Containers/UserSettings/UserSettings.tsx b/Containers/UserSettings/UserSettings.tsx index a927ade..7ab21a6 100644 --- a/Containers/UserSettings/UserSettings.tsx +++ b/Containers/UserSettings/UserSettings.tsx @@ -26,7 +26,7 @@ export default function UserSettings(props: UserSettingsProps) { useEffect(() => { const fetchWizardEnv = async () => { try { - const response = await fetch('/api/account/getWizardEnv', { + const response = await fetch('/api/v1/account/wizard-env', { method: 'GET', headers: { 'Content-type': 'application/json', diff --git a/Containers/UserSettings/UsernameSettings/UsernameSettings.tsx b/Containers/UserSettings/UsernameSettings/UsernameSettings.tsx index d3ad330..6ffb0a8 100644 --- a/Containers/UserSettings/UsernameSettings/UsernameSettings.tsx +++ b/Containers/UserSettings/UsernameSettings/UsernameSettings.tsx @@ -40,7 +40,7 @@ export default function UsernameSettings(props: UsernameSettingDTO) { setIsLoading(true); try { - const response = await fetch('/api/account/updateUsername', { + const response = await fetch('/api/v1/account/username', { method: 'PUT', headers: { 'Content-type': 'application/json', diff --git a/pages/api/v1/notif/apprise/send-test.ts b/pages/api/v1/notif/apprise/test.ts similarity index 100% rename from pages/api/v1/notif/apprise/send-test.ts rename to pages/api/v1/notif/apprise/test.ts diff --git a/pages/api/v1/notif/email/send-test.test.ts b/pages/api/v1/notif/email/test.test.ts similarity index 95% rename from pages/api/v1/notif/email/send-test.test.ts rename to pages/api/v1/notif/email/test.test.ts index f7b4c79..286f125 100644 --- a/pages/api/v1/notif/email/send-test.test.ts +++ b/pages/api/v1/notif/email/test.test.ts @@ -1,5 +1,5 @@ import { createMocks } from 'node-mocks-http'; -import handler from '~/pages/api/v1/notif/email/send-test'; +import handler from '~/pages/api/v1/notif/email/test'; import { getServerSession } from 'next-auth/next'; vi.mock('next-auth/next'); diff --git a/pages/api/v1/notif/email/send-test.ts b/pages/api/v1/notif/email/test.ts similarity index 100% rename from pages/api/v1/notif/email/send-test.ts rename to pages/api/v1/notif/email/test.ts diff --git a/pages/index.tsx b/pages/index.tsx index 06459dc..7e82143 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -15,7 +15,7 @@ export default function Index() { {/* */}