update
This commit is contained in:
1 parent
c7f4bad142
commit
9fd12d3e74
9 files changed
+787
-9
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import { type Plugin, type ViteDevServer } from "vite";
|
||||
import { readFileSync, mkdirSync, writeFileSync } from "fs";
|
||||
|
||||
export default function ytParsePlugin(): Plugin {
|
||||
return {
|
||||
name: "clipboard-server-spawn",
|
||||
configureServer(server: ViteDevServer) {
|
||||
server.ws.on("download-q", ({ q }) => {
|
||||
try {
|
||||
mkdirSync(`docs/${q}`);
|
||||
} catch (e) {}
|
||||
|
||||
let outMd = "";
|
||||
|
||||
const re = /^(?<min>\d{1,2}):(?<sec>\d{2})\s*$/;
|
||||
|
||||
for (const line of readFileSync(`docs/${q}.md`, "utf-8").trimEnd().split("\n")) {
|
||||
const m = re.exec(line);
|
||||
if (m) {
|
||||
const { min, sec } = m.groups!;
|
||||
const t = parseInt(min) * 60 + parseInt(sec);
|
||||
server.ws.send("seek-q", { t });
|
||||
outMd += `[${line}](./${q}/${t}.png)`;
|
||||
} else {
|
||||
outMd += line + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
writeFileSync(`docs/${q}.md`, outMd);
|
||||
});
|
||||
|
||||
server.ws.on("timed-q", ({ q, t, data }) => {
|
||||
writeFileSync(
|
||||
`docs/${q}/${t}.png`,
|
||||
data.replace(/^data:image\/png;base64,/, ""),
|
||||
"base64",
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user