From 155c347562becb73837e60bd07a316fa80f6c87d Mon Sep 17 00:00:00 2001 From: Octopus <66487668+J-P-S-O@users.noreply.github.com> Date: Tue, 30 Nov 2021 14:35:50 -0300 Subject: [PATCH 01/10] Update hyp.js --- bin/hyp.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/hyp.js b/bin/hyp.js index 043bdf4..f2bbf7c 100755 --- a/bin/hyp.js +++ b/bin/hyp.js @@ -15,6 +15,7 @@ import create from '../lib/commands/create.js' import seed from '../lib/commands/seed.js' import unseed from '../lib/commands/unseed.js' import beam from '../lib/commands/beam.js' +import alias from '../lib/commmands/alias.js' import driveLs from '../lib/commands/drive/ls.js' import driveCat from '../lib/commands/drive/cat.js' @@ -46,6 +47,7 @@ const commands = { unseed, create, beam, + alias, driveLs, driveCat, From 6c51530d5bb594e529ddc2de98bf6a902c9a1783 Mon Sep 17 00:00:00 2001 From: Octopus <66487668+J-P-S-O@users.noreply.github.com> Date: Tue, 30 Nov 2021 14:49:53 -0300 Subject: [PATCH 02/10] Create alias.js --- lib/commands/alias.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/commands/alias.js diff --git a/lib/commands/alias.js b/lib/commands/alias.js new file mode 100644 index 0000000..bb20fde --- /dev/null +++ b/lib/commands/alias.js @@ -0,0 +1,27 @@ +import chalk from 'chalk' + +const FULL_USAGE = ` + The alias command allows you to create aliases for the long urls... //I will think of something +` + +export default { + name: 'alias', + description: 'Create an alias for the urls', + usage: { + simple: '[alias] [full_url]', + full: FULL_USAGE + }, + command: async function (args) { + let url = args[1] + let alias = args[0] + if (!url || !alias){ + console.error(chalk.bold("Correct usage: "+"hyp alias [alias] [full_url]")) + } + + + process.once('SIGINT', () => { + + }) + + } +} From 46c4072efd3a81e2deed9711a463f023f286333d Mon Sep 17 00:00:00 2001 From: Octopus <66487668+J-P-S-O@users.noreply.github.com> Date: Tue, 30 Nov 2021 14:50:31 -0300 Subject: [PATCH 03/10] Update alias.js --- lib/commands/alias.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/commands/alias.js b/lib/commands/alias.js index bb20fde..269df30 100644 --- a/lib/commands/alias.js +++ b/lib/commands/alias.js @@ -1,8 +1,7 @@ import chalk from 'chalk' -const FULL_USAGE = ` - The alias command allows you to create aliases for the long urls... //I will think of something -` +const FULL_USAGE = ` The alias command allows you to create aliases for the long urls...` //I will think of something + export default { name: 'alias', From c549297e8d116398e2c4893cc873cc0062576624 Mon Sep 17 00:00:00 2001 From: Octopus <66487668+J-P-S-O@users.noreply.github.com> Date: Tue, 30 Nov 2021 14:51:13 -0300 Subject: [PATCH 04/10] Update alias.js --- lib/commands/alias.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/alias.js b/lib/commands/alias.js index 269df30..7035d93 100644 --- a/lib/commands/alias.js +++ b/lib/commands/alias.js @@ -14,7 +14,7 @@ export default { let url = args[1] let alias = args[0] if (!url || !alias){ - console.error(chalk.bold("Correct usage: "+"hyp alias [alias] [full_url]")) + console.error(chalk.bold("Correct usage: ")+"hyp alias [alias] [full_url]") } From d4904c106a69ebee72c96d6bd05f320b4e6c14ea Mon Sep 17 00:00:00 2001 From: jp Date: Tue, 30 Nov 2021 17:18:44 -0300 Subject: [PATCH 05/10] . --- lib/commands/alias.js | 18 +++++++++++++++++- lib/commands/beam.js | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/commands/alias.js b/lib/commands/alias.js index 7035d93..6390e09 100644 --- a/lib/commands/alias.js +++ b/lib/commands/alias.js @@ -1,5 +1,7 @@ import chalk from 'chalk' - +import os from 'os' +import path from 'path' +import fs from 'fs' const FULL_USAGE = ` The alias command allows you to create aliases for the long urls...` //I will think of something @@ -15,7 +17,21 @@ export default { let alias = args[0] if (!url || !alias){ console.error(chalk.bold("Correct usage: ")+"hyp alias [alias] [full_url]") + process.exit(0) + } + if (!String(url).startsWith("hyper://") || String(url).length != 72 ){ + console.error("Invalid url") + process.exit(0) + } + datadir = path.join(os.homedir(),".hyperdrive") + if (fs.existsSync(datadir)){ + + }else { + fs.mkdirSync(datadir) } + fs.writeFileSync(path.join(datadir,String(url).replace("hyper://","")),alias) + + process.once('SIGINT', () => { diff --git a/lib/commands/beam.js b/lib/commands/beam.js index c38efef..e63ec6a 100644 --- a/lib/commands/beam.js +++ b/lib/commands/beam.js @@ -10,7 +10,7 @@ const FULL_USAGE = ` On the sending device: - cat hello.txt | hyp beam "for bob roberts" + cat hello.txt | hyp beam "for bob roberts" On the receiving device: From c7ae45e6a464706f8defe7d91a1f3947f38e4ea7 Mon Sep 17 00:00:00 2001 From: jp Date: Tue, 30 Nov 2021 17:35:19 -0300 Subject: [PATCH 06/10] . --- lib/commands/alias.js | 10 +++++----- lib/commands/seed.js | 2 +- lib/urls.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/commands/alias.js b/lib/commands/alias.js index 6390e09..927905e 100644 --- a/lib/commands/alias.js +++ b/lib/commands/alias.js @@ -29,13 +29,13 @@ export default { }else { fs.mkdirSync(datadir) } - fs.writeFileSync(path.join(datadir,String(url).replace("hyper://","")),alias) - - - + if (fs.existsSync(path.join(datadir,String(url).replace("hyper://","")))){ + fs.rmSync(path.join(datadir,String(url).replace("hyper://",""))) + } + fs.writeFileSync(path.join(datadir,String(url).replace("hyper://","")),alias) process.once('SIGINT', () => { - + process.exit(0) }) } diff --git a/lib/commands/seed.js b/lib/commands/seed.js index ab330e1..4ec8790 100644 --- a/lib/commands/seed.js +++ b/lib/commands/seed.js @@ -24,7 +24,7 @@ export default { var keys = [] for (let url of args._) { let urlp = parseHyperUrl(url) - keys.push(urlp.hostname) + keys.push(urlp.hostname) } for (const key of keys) { diff --git a/lib/urls.js b/lib/urls.js index 4815a18..86f0f32 100644 --- a/lib/urls.js +++ b/lib/urls.js @@ -1,11 +1,11 @@ -import { parse } from 'url' +import { parse } from 'url' const SCHEME_REGEX = /[a-z]+:\/\//i // 1 2 3 4 const VERSION_REGEX = /^(hyper:\/\/)?([^/]+)(\+[^/]+)(.*)$/i export function parseHyperUrl (str, parseQS) { - // prepend the scheme if it's missing - if (!SCHEME_REGEX.test(str)) { + // prepend the scheme if it's missing and if the url has 64 characters (and therefore is not an alias) + if (!SCHEME_REGEX.test(str) && str.length === 64) { str = 'hyper://' + str } From d0ecdc91dec5f35ebed92bec4653c95f3e801f62 Mon Sep 17 00:00:00 2001 From: jp Date: Tue, 30 Nov 2021 17:50:12 -0300 Subject: [PATCH 07/10] . --- lib/urls.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/urls.js b/lib/urls.js index 86f0f32..b7570a9 100644 --- a/lib/urls.js +++ b/lib/urls.js @@ -1,4 +1,6 @@ import { parse } from 'url' +import { join } from 'path' +import { readFileSync, existsSync } from 'fs' const SCHEME_REGEX = /[a-z]+:\/\//i // 1 2 3 4 @@ -7,6 +9,13 @@ export function parseHyperUrl (str, parseQS) { // prepend the scheme if it's missing and if the url has 64 characters (and therefore is not an alias) if (!SCHEME_REGEX.test(str) && str.length === 64) { str = 'hyper://' + str + }else{ + str = join(os.homedir(),".hyperdrive",str) + if (existsSync(str)){ + str = readFileSync(str) + } else { + throw new Error("Invalid url or alias") + } } var parsed, version = null, match = VERSION_REGEX.exec(str) @@ -15,6 +24,7 @@ export function parseHyperUrl (str, parseQS) { parsed = parse((match[1] || '') + (match[2] || '') + (match[4] || ''), parseQS) version = match[3].slice(1) } else { + parsed = parse(str, parseQS) } parsed.href = str // overwrite href to include actual original From 1e91ab493d8c4411f2fca6aa098ca786b1d76928 Mon Sep 17 00:00:00 2001 From: jp Date: Wed, 1 Dec 2021 15:08:37 -0300 Subject: [PATCH 08/10] . --- bin/hyp.js | 2 +- lib/usage.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/hyp.js b/bin/hyp.js index f2bbf7c..78a55f6 100755 --- a/bin/hyp.js +++ b/bin/hyp.js @@ -15,7 +15,7 @@ import create from '../lib/commands/create.js' import seed from '../lib/commands/seed.js' import unseed from '../lib/commands/unseed.js' import beam from '../lib/commands/beam.js' -import alias from '../lib/commmands/alias.js' +import alias from '../lib/commands/alias.js' import driveLs from '../lib/commands/drive/ls.js' import driveCat from '../lib/commands/drive/cat.js' diff --git a/lib/usage.js b/lib/usage.js index 1a8b581..0bd6abc 100644 --- a/lib/usage.js +++ b/lib/usage.js @@ -4,7 +4,7 @@ export default function usage (commands, err, cmd) { if (err) { console.error(chalk.red(`${err}\n`)) } else { - console.error('') + console.error('') } if (cmd) { @@ -22,7 +22,7 @@ ${chalk.bold(`General Commands:`)} ${simple(commands.seed)} ${simple(commands.unseed)} ${simple(commands.create)} - + ${simple(commands.alias)} ${simple(commands.beam)} ${chalk.bold(`Hyperdrive Commands:`)} From 20d03e24347866fba84301b48300b7da9f34fef7 Mon Sep 17 00:00:00 2001 From: jp Date: Thu, 2 Dec 2021 11:42:22 -0300 Subject: [PATCH 09/10] . --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0febddc..866e422 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ General Commands: hyp seed {urls...} - Download and make hyper data available to the network. hyp unseed {urls...} - Stop making hyper data available to the network. hyp create {drive|bee} - Create a new hyperdrive or hyperbee. - + hyp alias [alias] [full_url] - Create an alias for the urls. hyp beam {pass_phrase} - Send a stream of data over the network. Hyperdrive Commands: From 9b634413f201c265be1e2b2d7751442d8898232f Mon Sep 17 00:00:00 2001 From: jp Date: Thu, 2 Dec 2021 11:42:48 -0300 Subject: [PATCH 10/10] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 866e422..fe1d7ee 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ General Commands: hyp seed {urls...} - Download and make hyper data available to the network. hyp unseed {urls...} - Stop making hyper data available to the network. hyp create {drive|bee} - Create a new hyperdrive or hyperbee. - hyp alias [alias] [full_url] - Create an alias for the urls. + hyp alias [alias] [full_url] - Create an alias for the urls. hyp beam {pass_phrase} - Send a stream of data over the network. Hyperdrive Commands: