From fd94dd6e619a21fa02545654d143141d29793d40 Mon Sep 17 00:00:00 2001 From: William Bell Date: Mon, 17 Jul 2023 20:42:49 +0100 Subject: [PATCH] make store files --- .gitattributes | 2 - .gitignore | 132 +++---------------------------------- .vscode/settings.json | 5 ++ LICENSE | 21 ------ app.ar | 13 ++++ argon-package.json | 4 ++ config.ar | 1 + iso-lock.json | 1 + randstr.ar | 7 ++ routes/isotope/download.ar | 23 +++++++ routes/isotope/push.ar | 27 ++++++++ routes/isotope/search.ar | 24 +++++++ save.ar | 28 ++++++++ server.ar | 7 ++ 14 files changed, 148 insertions(+), 147 deletions(-) delete mode 100644 .gitattributes create mode 100644 .vscode/settings.json delete mode 100644 LICENSE create mode 100644 app.ar create mode 100644 argon-package.json create mode 100644 config.ar create mode 100644 iso-lock.json create mode 100644 randstr.ar create mode 100644 routes/isotope/download.ar create mode 100644 routes/isotope/push.ar create mode 100644 routes/isotope/search.ar create mode 100644 save.ar create mode 100644 server.ar diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/.gitignore b/.gitignore index 20b0c92..fde1c2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,127 +1,11 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* +.DS_Store -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json +# isotope +__isotope__ -# Runtime data -pids -*.pid -*.seed -*.pid.lock +# argon +argon_modules -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variable files -.env -.env.development.local -.env.test.local -.env.production.local -.env.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next -out - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# vuepress v2.x temp and cache directory -.temp -.cache - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* +# main +packages +packages-db.json \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5d25211 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "*.ar": "lua" + } +} diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 3f5a2a0..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 William Bell - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/app.ar b/app.ar new file mode 100644 index 0000000..5613c93 --- /dev/null +++ b/app.ar @@ -0,0 +1,13 @@ +import "server" as * +import "config" as * +import "save" + +# routes + + +# isotope +import "routes/isotope/push" as * +import "routes/isotope/search" as * +import "routes/isotope/download" as * + +app.run() \ No newline at end of file diff --git a/argon-package.json b/argon-package.json new file mode 100644 index 0000000..60fe980 --- /dev/null +++ b/argon-package.json @@ -0,0 +1,4 @@ +{ + "name": "isotope-server", + "version": "1.0.0" +} \ No newline at end of file diff --git a/config.ar b/config.ar new file mode 100644 index 0000000..67d2465 --- /dev/null +++ b/config.ar @@ -0,0 +1 @@ +let url = "http://localhost:7030" \ No newline at end of file diff --git a/iso-lock.json b/iso-lock.json new file mode 100644 index 0000000..e693fb7 --- /dev/null +++ b/iso-lock.json @@ -0,0 +1 @@ +[{"Name":"http.ar","Version":"1.0.0","URL":"http://localhost:7030/isotope-download?version=latest\u0026name=http.ar"}] diff --git a/randstr.ar b/randstr.ar new file mode 100644 index 0000000..73292be --- /dev/null +++ b/randstr.ar @@ -0,0 +1,7 @@ + +let randstr(length) = do + let chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + let id = "" + for (i from 0 to length) do + id = id + chars[random.int(0, chars.length-1)] + return id diff --git a/routes/isotope/download.ar b/routes/isotope/download.ar new file mode 100644 index 0000000..1b519c6 --- /dev/null +++ b/routes/isotope/download.ar @@ -0,0 +1,23 @@ +import "../server" as * +import "../config" as * +import "../save" as * + +let search(req, res) = do + let name = req.query.name + let version = req.query.version + let package = packages.get(name) + if (package == null) do + res.code = 404 + res.send("Package not found") + return + let currentVersion = package.versions.get(version) + forever do + let redirect = currentVersion.get("redirect") + if (redirect) do + currentVersion = package.versions.get(redirect) + continue + break + let filename = currentVersion.get("filename") + let p = path.join([program.cwd,"packages", name, filename]) + res.sendFile(p) +app.route("/isotope-download", null, search) diff --git a/routes/isotope/push.ar b/routes/isotope/push.ar new file mode 100644 index 0000000..e0d88dc --- /dev/null +++ b/routes/isotope/push.ar @@ -0,0 +1,27 @@ +import "../server" as * +import "../randstr" as * +import "../save" as * + +let push(req, res) = do + let name = req.formdata.name + let version = req.formdata.version + let file = req.files.file + let package = packages.get(name) + if (package == null) do + package = {versions:{}} + packages[name] = package + let currentVersion = package.versions.get(version) + let directory = path.join([program.cwd, "packages", name]) + if (currentVersion == null) do + currentVersion = {name:name, version:version} + package.versions[version] = currentVersion + let filename = version+".tar.gz" + let p = path.join([directory, filename]) + term.log(directory) + path.mkAllDir(directory) + file.save(p) + currentVersion.filename = filename + package.versions['latest'] = {redirect: version} + changes.n = changes.n + 1 + res.send("OK") +app.route("/isotope-push", ['POST'], push) \ No newline at end of file diff --git a/routes/isotope/search.ar b/routes/isotope/search.ar new file mode 100644 index 0000000..660e444 --- /dev/null +++ b/routes/isotope/search.ar @@ -0,0 +1,24 @@ +import "../server" as * +import "../config" as config +import "../save" as * +import "http.ar/url" as urllib + +let search(req, res) = do + let name = req.query.name + let version = req.query.version + let package = packages.get(name) + if (package == null) do + res.code = 404 + res.send("Package not found") + return + let currentVersion = package.versions.get(version) + forever do + let redirect = currentVersion.get("redirect") + if (redirect) do + currentVersion = package.versions.get(redirect) + continue + break + let filename = currentVersion.get("filename") + let URL = config.url+"/isotope-download?"+urllib.queryStr({name:currentVersion.name, version:currentVersion.version}) + res.json({Name: currentVersion.name, Version: currentVersion.version, URL:URL }) +app.route("/isotope-search", null, search) diff --git a/save.ar b/save.ar new file mode 100644 index 0000000..987b9d5 --- /dev/null +++ b/save.ar @@ -0,0 +1,28 @@ +let packages = {} +let savePath = path.join([program.cwd, "packages-db.json"]) + +let changes = {n: 0, last: 0} + +let load() = do + if (path.exists(savePath)) do + let file = file.read(savePath) + packages = file.json() + file.close() + +let save() = do + if (changes.n == changes.last) return + let file = file.write(savePath) + file.json(packages) + file.close() + +let saveThread() = do + while (true) do + try do + save() + catch (e) do + term.log(e) + time.snooze(10) + +load() +t = thread(saveThread) +t.start() \ No newline at end of file diff --git a/server.ar b/server.ar new file mode 100644 index 0000000..6a1b748 --- /dev/null +++ b/server.ar @@ -0,0 +1,7 @@ +import "http.ar" as http + +let app = http.server() + +app.use(http.logger) +app.use(http.formdata) +app.port = 7030 \ No newline at end of file