Skip to content

Commit ca67346

Browse files
authored
Merge pull request #51 from LocalBytes/fix/perf
feat: Read in line by line to find data
2 parents e5de069 + 480539b commit ca67346

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

packages/localdeck-configurator/src/pages/editor.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,6 @@ const reset = () => {
153153
config.resetChanges();
154154
resetting.value = false;
155155
};
156+
157+
preloadComponents(['DeckButtonConfigLabel', 'DeckIconPicker']);
156158
</script>
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
import * as fs from 'fs/promises';
1+
import * as fs from 'node:fs';
2+
import * as readline from 'node:readline';
23

34
import { decompress } from '@localbytes/localdeck-components/src/utils/compression';
45
import { zPadEditor } from '@localbytes/localdeck-components/src/utils/PadCfg';
56

67
export default defineEventHandler(async (event) => {
78
const { filesDir } = useRuntimeConfig();
89
const { filename } = getQuery(event);
9-
const content = await fs.readFile(`${filesDir}/${filename}`, 'utf8');
10-
const configMatch = content.match(/configurator\?config=(.*)/);
10+
const content = fs.createReadStream(`${filesDir}/${filename}`, 'utf8');
11+
const rl = readline.createInterface({ input: content, crlfDelay: Infinity });
12+
13+
let configMatch = null;
14+
let matchName = null;
15+
let matchFriendly = null;
16+
17+
for await (const line of rl) {
18+
configMatch ??= line.match(/localdeck-configurator\?config=(.*)/);
19+
matchName ??= line.match(/name: "?(.*)"?/);
20+
matchFriendly ??= line.match(/friendly_name: "?(.*)"?/);
21+
22+
// noinspection PointlessBooleanExpressionJS
23+
if (configMatch) break;
24+
}
25+
1126
const configStr = configMatch ? decodeURIComponent(configMatch[1]) : null;
1227

1328
const config = configStr
1429
? decompress(configStr, zPadEditor)
1530
: zPadEditor.parse({});
1631

17-
const matchName = content.match(/name: (.*)/);
18-
if (matchName) config.title = matchName[1];
19-
20-
const matchFriendly = content.match(/friendly_name: (.*)/);
21-
if (matchFriendly) config.title = matchFriendly[1];
22-
32+
config.title = matchFriendly?.[1] ?? matchName?.[1] ?? config.title ?? 'My LocalDeck';
2333
config.buttons ??= {};
2434

25-
return { configStr, config, content };
35+
return { configStr, config };
2636
});

0 commit comments

Comments
 (0)