Skip to content

Commit 1dc1fb1

Browse files
author
3aa49ec6bfc910647fa1c5a013e48eef
committed
Moved code from api to page.ts
1 parent a6faa38 commit 1dc1fb1

File tree

6 files changed

+27
-58
lines changed

6 files changed

+27
-58
lines changed

website/.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ module.exports = {
3030
],
3131
rules: {
3232
"@typescript-eslint/no-unused-vars": "off",
33+
"@typescript-eslint/no-explicit-any": "off",
3334
}
3435
};

website/src/routes/+page.svelte

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,15 @@
11
<script lang="ts">
2+
import type { Data } from './+page.js';
23
import { onMount } from 'svelte';
34
4-
let a = 0;
5-
let b = 0;
6-
let total = 0;
5+
export let data: Data;
6+
77
let logFiles: string[] = [];
88
let configFiles: string[] = [];
99
let finishedApiCalls = false;
1010
let lockChimes: any[] = [];
1111
let selectedUrl = '';
1212
13-
async function add() {
14-
const response = await fetch('/api/dashboard', {
15-
method: 'GET',
16-
body: JSON.stringify({ a, b }),
17-
headers: {
18-
'content-type': 'application/json'
19-
}
20-
});
21-
22-
total = await response.json();
23-
}
24-
25-
async function listLogFiles() {
26-
const response = await fetch('/api/logFiles', {
27-
method: 'GET',
28-
headers: {
29-
'content-type': 'application/json'
30-
}
31-
});
32-
33-
const logFiles = await response.json();
34-
console.log(logFiles.logFiles);
35-
36-
return logFiles.logFiles;
37-
}
38-
39-
async function listConfigFiles() {
40-
const response = await fetch('/api/configFiles', {
41-
method: 'GET',
42-
headers: {
43-
'content-type': 'application/json'
44-
}
45-
});
46-
47-
const configFiles = await response.json();
48-
console.log(configFiles.configFiles);
49-
50-
return configFiles.configFiles;
51-
}
5213
5314
async function getLockChimes() {
5415
const response = await fetch('/api/lockChimes', {
@@ -78,10 +39,9 @@
7839
};
7940
8041
onMount(async () => {
81-
logFiles = await listLogFiles();
82-
configFiles = await listConfigFiles();
42+
logFiles = data.logFiles;
43+
configFiles = data.configFiles;
8344
lockChimes = await getLockChimes();
84-
console.log(logFiles);
8545
finishedApiCalls = true;
8646
});
8747
</script>

website/src/routes/+page.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { Load } from '@sveltejs/kit';
2+
import { logNameToPathMapping, configNameToPathMapping } from '$lib/constants';
3+
4+
export const load: Load = async ({ params }) => {
5+
6+
const logNames = Object.keys(logNameToPathMapping);
7+
const configNames = Object.keys(configNameToPathMapping);
8+
9+
return {
10+
logFiles: logNames,
11+
configFiles: configNames,
12+
};
13+
};
14+
15+
export interface Data {
16+
logFiles: string[];
17+
configFiles: string[];
18+
// lockChimes remain as API due to CORS
19+
}

website/src/routes/api/logFiles/[logName]/+server.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ const getLogContent = (logName: string): string => {
1717
}
1818
};
1919

20-
// const deleteLogFile = (logName: string | undefined): void => {
21-
// const logPath = logNameToPathMapping[logName ?? ""];
22-
// if (!logPath || !existsSync(logPath)) {
23-
// return;
24-
// }
25-
26-
// try {
27-
// unlinkSync(logPath);
28-
// } catch (err) {
29-
// console.error(`Error deleting file: ${err}`);
30-
// }
31-
// }
32-
3320
const clearLogFile = (logPath: string | undefined) => {
3421

3522
console.log("clearLogFile:",logPath)

website/src/routes/editConfig/[configName]/+page.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
});
6464
</script>
6565

66+
<h1>Config file: {configName}</h1>
67+
6668
<div class="p-2">
6769
<div class="border border-gray-200 p-2 text-sm">
6870
<EditorContent editor={$editor} />

0 commit comments

Comments
 (0)