From ec50750d2fd5e5e82384a6ef3b7187189f614538 Mon Sep 17 00:00:00 2001 From: William Bell Date: Sun, 25 Feb 2024 13:14:13 +0000 Subject: [PATCH] improve home page and add limits to name and version --- .env | 9 +++++--- config.ar | 3 +++ database.ar | 13 ++++++++--- routes/isotope/download.ar | 5 ++++ routes/isotope/push.ar | 4 ++++ routes/isotope/search.ar | 5 ++++ routes/website/home.ar | 8 ++++++- routes/website/package.ar | 8 ++++++- static/styles.css | 1 + templates/index.html | 47 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 95 insertions(+), 8 deletions(-) diff --git a/.env b/.env index a516180..348a59e 100644 --- a/.env +++ b/.env @@ -1,3 +1,6 @@ -URL="https://change-me.com" -domain="change-me.com" -port="7030" # default port for the server \ No newline at end of file +URL="https://change-me.com" # all urls should be in the format https://change-me.com +domain="change-me.com" # domain name +port="7030" # default port for the server + +discord_URL="https://discord.gg/XKN79yDa5t" # discord invite link +source_code_URL="https://github.com/Open-Argon/isotope-server" # source code link \ No newline at end of file diff --git a/config.ar b/config.ar index 9b1e819..206226c 100644 --- a/config.ar +++ b/config.ar @@ -1,6 +1,9 @@ let url = env.get_value("URL","https://isotope.wbell.dev") term.log("URL: "+url) +let default_domain = "isotope.wbell.dev" let domain = env.get_value("domain","isotope.wbell.dev") +let discord_URL = env.get_value("discord_URL","https://discord.com/invite/XKN79yDa5t") +let source_code_URL = env.get_value("source_code_URL","https://github.com/Open-Argon/isotope-server") term.log("domain: "+domain) let port = number(env.get_value("PORT", 7030)) term.log("port: "+port) diff --git a/database.ar b/database.ar index 2044fba..8dac88f 100644 --- a/database.ar +++ b/database.ar @@ -5,11 +5,18 @@ let savePath = path.join([program.cwd, 'data', "packages-db.json"]) let changes = {n: 0, last: 0} +let validVersion(version) = do + if (version.length < 1 || version.length > 16) return false + for (i from 0 to version.length) do + if (i > 0 && i < version.length-1 && version[i] not in "abcdefghijklmnopqrstuvwxyz0123456789-.") return false + else if (version[i] not in "abcdefghijklmnopqrstuvwxyz0123456789") return false + return true + let validName(name) = do - if (name.length < 3) return false - if (name.length > 32) return false + if (name.length < 3 || name.length > 32) return false for (i from 0 to name.length) do - if (name[i] not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.") return false + if (i > 0 && i < name.length-1 && name[i] not in "abcdefghijklmnopqrstuvwxyz0123456789-.") return false + else if (name[i] not in "abcdefghijklmnopqrstuvwxyz0123456789") return false return true let makeChange() = changes.n += 1 diff --git a/routes/isotope/download.ar b/routes/isotope/download.ar index df3a61d..f51c210 100644 --- a/routes/isotope/download.ar +++ b/routes/isotope/download.ar @@ -4,6 +4,11 @@ import "database" as * let download(req, res) = do let name = req.query.get_value("name", null) + if (name == null) do + res.code = 400 + res.send("Name is required") + return + name = name.toLower() let version = req.query.get_value("version", "latest") let package = packages.get_value(name) if (package == null) do diff --git a/routes/isotope/push.ar b/routes/isotope/push.ar index 488d05b..0e1a022 100644 --- a/routes/isotope/push.ar +++ b/routes/isotope/push.ar @@ -19,6 +19,10 @@ let push(req, res) = do if (package == null) do res.code = 404 return res.send("Package not found") + if (version not in package.versions.keys() && not validName(version)) do + res.code = 400 + res.send("Invalid version type") + return let acc = account.getByToken(req.headers.get_value("isotope-auth", "")) if (acc == null) do res.code = 403 diff --git a/routes/isotope/search.ar b/routes/isotope/search.ar index 28a69a1..a72c17c 100644 --- a/routes/isotope/search.ar +++ b/routes/isotope/search.ar @@ -5,6 +5,11 @@ import "url.ar" as urllib let search(req, res) = do let name = req.query.get_value("name", null) + if (name == null) do + res.code = 400 + res.send("Name is required") + return + name = name.toLower() let version = req.query.get_value("version", "latest") let package = packages.get_value(name) if (package == null) do diff --git a/routes/website/home.ar b/routes/website/home.ar index 68458bc..af212cc 100644 --- a/routes/website/home.ar +++ b/routes/website/home.ar @@ -1,6 +1,12 @@ import "server" as * import "database" as * +import "config" as config let home(req, res) = do - res.renderTemplate("index.html", {}) + let push_command = "isotope package push" + let push_command_latest = "isotope package push --latest" + if (config.default_domain != config.domain) do + push_command += " " + config.domain + push_command_latest += " " + config.domain + res.renderTemplate("index.html", {discord_URL: config.discord_URL, source_code_URL: config.source_code_URL, push_command: push_command, push_command_quote: push_command.replace("'", "\\'"), push_command_latest: push_command_latest, push_command_latest_quote: push_command_latest.replace("'", "\\'")}) app.get("/", home) \ No newline at end of file diff --git a/routes/website/package.ar b/routes/website/package.ar index 566c2f9..836aee8 100644 --- a/routes/website/package.ar +++ b/routes/website/package.ar @@ -1,4 +1,5 @@ import "server" as * +import "config" as config import "database" as * import "url.ar" as url import "bleach.ar" as bleach @@ -17,7 +18,12 @@ let package(req, res) = do let version = req.query.get_value("version", "latest") let commandName = name if (version != "latest") commandName += "@"+version - let command = shlex.join(["isotope", "install", commandName]) + let command = ["isotope", "install"] + if (config.default_domain != config.domain) do + command.append("--remote") + command.append(config.domain) + command.append(commandName) + command = shlex.join(command) let package = packages.get_value(name) if (package == null && version == "latest") do package = {versions:{}, order:{}, name:name} diff --git a/static/styles.css b/static/styles.css index bf4427e..459d6e1 100644 --- a/static/styles.css +++ b/static/styles.css @@ -14,6 +14,7 @@ body { padding: 0; color: var(--text); background-color: var(--background); + margin-bottom: 2rem; } a { diff --git a/templates/index.html b/templates/index.html index edc4328..50e1318 100644 --- a/templates/index.html +++ b/templates/index.html @@ -45,6 +45,8 @@ + +
@@ -132,6 +134,51 @@
+
+

What is Isotope?

+

+ Isotope is the official package manager for + Argon. It is a simple, fast, and secure package manager for + Argon. It is designed to be easy to use and easy to install. +

+

How do I install Isotope?

+

+ Isotope comes pre-packaged with Open Argon's official distribution of the Argon programming language. + If you would like to compile Isotope from source, you can find the source code at https://github.com/Open-Argon/Isotope and follow the instructions in the README. +

+

How do I use Isotope?

+

to access the help menu in isotope, run the following command inside the terminal:

+
isotope help
📋 Click to Copy
+

If you need any further assistance, please feel free to reach out to us on our Discord server.

+

How do I host my own Isotope Server?

+

+ If you would like to host your own Isotope server, you can find the source code at {{source_code_URL}}. + All you need to do is follow the instructions in the README. If you need any further assistance, please feel free to reach out to us on our Discord server. +

+

How do I make and upload a package to Isotope?

+

+ If you would like to upload a package to Isotope, login or register then create an empty folder and run the following command inside the terminal: +

+
isotope init
📋 Click to Copy
+

Edit "argon-package.json" and choose a name and version of your package. Note: all names and versions sent to this server have to be lowercase alpha-numeric characters, and can also include "-" and ".". The first and last characters can only be alpha-numeric. All names have to be between 3 and 32 characters long, and all versions types cannot be greater than 16 characters long.

+

Then make a folder called "src" inside the folder you just created, and write all your code inside the folder. Remember, for a package, its recommended to name the main file "init.ar".

+

Once you have written your code, run the following command inside the terminal:

+
isotope package build
📋 Click to Copy
+

make sure you are in the same folder as "argon-package.json".

+

Then run the following command inside the terminal:

+
{{push_command}}
📋 Click to Copy
+

again, make sure you are in the same folder as "argon-package.json".

+

If you are ready to make a full stable release, run the following command:

+
{{push_command_latest}}
📋 Click to Copy
+

again, make sure you are in the same folder as "argon-package.json".

+

If you need any further assistance, please feel free to reach out to us on our Discord server.

+