mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-15 23:19:26 +08:00
48 lines
1.0 KiB
Python
48 lines
1.0 KiB
Python
import glob
|
|
import os.path
|
|
from pathlib import Path
|
|
|
|
PRE = '''#include "server.hpp"
|
|
|
|
std::map<
|
|
std::string,
|
|
CrackerServer::WebPage
|
|
> CrackerServer::WebRes = {
|
|
'''
|
|
|
|
POST = "};"
|
|
|
|
TYPE_MAP = {
|
|
".html": "text/html; charset=utf-8",
|
|
".js": "application/javascript",
|
|
".css": "text/css",
|
|
".png": "image/png",
|
|
".jpeg": "image/jpeg",
|
|
".ico": "image/x-icon",
|
|
}
|
|
|
|
def main():
|
|
root = "./webui/dist"
|
|
dist = [
|
|
"./webui/dist/*.*",
|
|
"./webui/dist/**/*.*"
|
|
]
|
|
|
|
l = []
|
|
for i in dist:
|
|
l += glob.glob(i)
|
|
|
|
with open(file="./webpage.cpp", mode="w", encoding="utf-8") as f:
|
|
f.write(PRE)
|
|
for i in l:
|
|
print(f"Use {i}")
|
|
with open(file=i, mode="r+b") as raw:
|
|
content = raw.read()
|
|
path = os.path.relpath(i, root).replace('\\', '/')
|
|
f.write(f'''{{"/{path}", {{"{TYPE_MAP[Path(i).suffix]}",{{ {", ".join([hex(b) for b in content])} }} }} }},\n''')
|
|
f.write(POST)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|