1
mirror of https://github.com/cocktailpeanut/dalai synced 2024-11-23 04:16:53 +01:00

fix the https issue

was using webcrypto sha256 to generate unique ID for messages but it was too much hassle when trying to use it on http that's not localhost (such as 0.0.0.0) so just started using timestamp + random number instead.
This commit is contained in:
cocktailpeanut 2023-03-18 01:21:40 -04:00
parent 6145e97138
commit 2cfe069aa2
5 changed files with 40 additions and 42 deletions

View File

@ -180,7 +180,9 @@ form.addEventListener('submit', (e) => {
e.stopPropagation()
if (input.textContent) {
config.prompt = input.textContent
config.id = "TS-" + Date.now() + "-" + Math.floor(Math.random() * 100000)
socket.emit('request', config)
config.id = null
loading(config.prompt)
input.textContent = "";
}
@ -226,7 +228,7 @@ socket.on('result', async ({ request, response }) => {
} else {
if (response == "\n\n<end>") {
} else {
const id = await sha256(request.prompt)
const id = request.id
let existing = document.querySelector(`[data-id='${id}']`)
if (existing) {
existing.textContent = existing.textContent + response

View File

@ -12,7 +12,7 @@ const { io } = require("socket.io-client");
const term = require( 'terminal-kit' ).terminal;
const Downloader = require("nodejs-file-downloader");
const semver = require('semver');
const _7z = require('7zip-min');
//const _7z = require('7zip-min');
const axios = require('axios')
const platform = os.platform()
const shell = platform === 'win32' ? 'powershell.exe' : 'bash';
@ -111,34 +111,34 @@ class Dalai {
console.log("cleaning up temp files")
await fs.promises.rm(path.resolve(this.home, filename))
}
async mingw() {
const mingw = "https://github.com/niXman/mingw-builds-binaries/releases/download/12.2.0-rt_v10-rev2/x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z"
const downloader = new Downloader({
url: mingw,
directory: this.home,
onProgress: (percentage, chunk, remainingSize) => {
this.progress("download mingw", percentage)
},
});
try {
await this.startProgress("download mingw")
await downloader.download();
} catch (error) {
console.log(error);
}
this.progressBar.update(1);
await new Promise((resolve, reject) => {
_7z.unpack(path.resolve(this.home, "x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z"), this.home, (err) => {
if (err) {
reject(err)
} else {
resolve()
}
})
})
console.log("cleaning up temp files")
await fs.promises.rm(path.resolve(this.home, "x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z"))
}
// async mingw() {
// const mingw = "https://github.com/niXman/mingw-builds-binaries/releases/download/12.2.0-rt_v10-rev2/x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z"
// const downloader = new Downloader({
// url: mingw,
// directory: this.home,
// onProgress: (percentage, chunk, remainingSize) => {
// this.progress("download mingw", percentage)
// },
// });
// try {
// await this.startProgress("download mingw")
// await downloader.download();
// } catch (error) {
// console.log(error);
// }
// this.progressBar.update(1);
// await new Promise((resolve, reject) => {
// _7z.unpack(path.resolve(this.home, "x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z"), this.home, (err) => {
// if (err) {
// reject(err)
// } else {
// resolve()
// }
// })
// })
// console.log("cleaning up temp files")
// await fs.promises.rm(path.resolve(this.home, "x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z"))
// }
async query(req, cb) {
console.log(`> query:`, req)
@ -205,6 +205,11 @@ class Dalai {
}
}
async install(core, ...models) {
const venv_path = path.join(this.home, "venv")
let ve = await exists(venv_path)
if (!ve) {
await this.setup()
}
// first install
let engine = this.cores[core]
let e = await exists(path.resolve(engine.home));

5
package-lock.json generated
View File

@ -1,16 +1,15 @@
{
"name": "dalai",
"version": "0.2.23",
"version": "0.2.26",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "dalai",
"version": "0.2.23",
"version": "0.2.26",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"7zip-min": "^1.4.4",
"axios": "^1.3.4",
"ejs": "^3.1.8",
"express": "^4.18.2",

View File

@ -1,6 +1,6 @@
{
"name": "dalai",
"version": "0.2.23",
"version": "0.2.26",
"description": "",
"main": "index.js",
"author": "cocktailpeanut",
@ -16,7 +16,6 @@
"postinstall": "node setup"
},
"dependencies": {
"7zip-min": "^1.4.4",
"axios": "^1.3.4",
"ejs": "^3.1.8",
"express": "^4.18.2",

View File

@ -41,13 +41,6 @@
resolved "https://registry.npmjs.org/7zip-bin/-/7zip-bin-5.1.1.tgz"
integrity sha512-sAP4LldeWNz0lNzmTird3uWfFDWWTeg6V/MsmyyLR9X1idwKBWIgt/ZvinqQldJm3LecKEs1emkbquO6PCiLVQ==
"7zip-min@^1.4.4":
version "1.4.4"
resolved "https://registry.npmjs.org/7zip-min/-/7zip-min-1.4.4.tgz"
integrity sha512-mYB1WW5tcXfZxUN4+2joKk4+6j8jp+mpO2YiMU5z1gNNFbACxI2ADasffsdNPovZSwn/E662ZIH5gRkFPMufmA==
dependencies:
"7zip-bin" "5.1.1"
accepts@~1.3.4, accepts@~1.3.8:
version "1.3.8"
resolved "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz"