Skip to content

Commit

Permalink
Fix for typeroots
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandostaler committed Apr 2, 2024
1 parent fc7e226 commit d9f5393
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Use Node.js 18
- name: Use Node.js 21
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 21

- name: Install dependencies
run: yarn
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Use Node.js 18
- name: Use Node.js 21
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 21

- name: Install dependencies
run: yarn
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ release/

.env
idée.txt
appwrite/appwrite.tar.gz
51 changes: 35 additions & 16 deletions appwrite/main.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
const fetch2 = require('node-fetch');
const axios = require('axios');

module.exports = async (req, res) => {
module.exports = async ({ req, res }) => {
console.log("Starting function");

// console.log("req: ", req);
// console.log("res", res);

var payloadString = "";
if (req.payload) {
payloadString = req.payload;
} else if (req.body) {
payloadString = req.body;
} else if (req.query) {
payloadString = req.query;
} else {
return res.json({ message: "No payload found!" }, 400)
}

// console.log('payloadString: ', payloadString)

try {
const payload = JSON.parse(req.payload)
const payload = JSON.parse(payloadString)

const type = payload["type"];

if (type == "cse") {
const query = payload["query"];
console.log('query: ', query)

// console.log(process.env.GOOGLE_API_KEY)

const google_api_key =
req.variables.GOOGLE_API_KEY ||
process.env.GOOGLE_API_KEY ||
console.log('GOOGLE_API_KEY variable not found. You can set it in Function settings.');

const google_cse_id =
req.variables.GOOGLE_CSE_ID ||
process.env.GOOGLE_CSE_ID ||
console.log('GOOGLE_CSE_ID variable not found. You can set it in Function settings.');

var fetch_res = await fetch2(
Expand All @@ -27,14 +45,14 @@ module.exports = async (req, res) => {
)}`
);

// console.log(fetch_res.status)
// console.log('fetch_res: ', fetch_res)

if (fetch_res.status != 200) {
res.json({ message: "status not 200! " + (await fetch_res.text()) }, fetch_res.status)
return res.json({ message: "status not 200! " + (await fetch_res.text()) }, fetch_res.status)
} else {
var j = await fetch_res.json();
// console.log(j)
res.json(j, fetch_res.status)
return res.json(j, fetch_res.status)
}
} else if (type == "cors") {
const url = payload["url"];
Expand All @@ -43,35 +61,36 @@ module.exports = async (req, res) => {
const config = { headers: options.headers }
if (options.method == "GET") {
axios_res = axios.get(url, config).catch(error => {
res.json({ message: "Error: " + error }, 400)
return res.json({ message: "Error: " + error }, 400)
});
} else if (options.method == "POST") {
axios_res = axios.post(url, options.body, config).catch(error => {
res.json({ message: "Error: " + error }, 400)
return res.json({ message: "Error: " + error }, 400)
});
} else if (options.method == "PUT") {
axios_res = axios.put(url, options.body, config).catch(error => {
res.json({ message: "Error: " + error }, 400)
return res.json({ message: "Error: " + error }, 400)
});
} else if (options.method == "PATCH") {
axios_res = axios.patch(url, options.body, config).catch(error => {
res.json({ message: "Error: " + error }, 400)
return res.json({ message: "Error: " + error }, 400)
});
} else if (options.method == "DELETE") {
axios_res = axios.delete(url, options.body).catch(error => {
res.json({ message: "Error: " + error }, 400)
return res.json({ message: "Error: " + error }, 400)
});
}

axios_res.then(resp => {
res.json({ message: resp.data }, resp.status);
return res.json({ message: resp.data }, resp.status);
}).catch(error => {
res.json({ message: "Error: " + error }, 400)
return res.json({ message: "Error: " + error }, 400)
})
} else {
res.json({ message: "Invalid type!" }, 400)
return res.json({ message: "Invalid type!" }, 400)
}
} catch (error) {
res.json({ message: "An error occured!" }, 400)
console.log('error: ', error)
return res.json({ message: "An error occured!" }, 400)
}
};
2 changes: 1 addition & 1 deletion dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if (!self.define) {
});
};
}
define(['./workbox-340e2aff'], (function (workbox) { 'use strict';
define(['./workbox-148cb7e5'], (function (workbox) { 'use strict';

self.skipWaiting();
workbox.clientsClaim();
Expand Down
65 changes: 50 additions & 15 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
Expand All @@ -17,18 +21,49 @@
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
"@icon/*": ["./src/assets/icons/*"],
"@type/*": ["./src/types/*"],
"@store/*": ["./src/store/*"],
"@hooks/*": ["./src/hooks/*"],
"@constants/*": ["./src/constants/*"],
"@api/*": ["./src/api/*"],
"@components/*": ["./src/components/*"],
"@utils/*": ["./src/utils/*"],
"@src/*": ["./src/*"],
"@openai_function_calling_tools/*": ["./src/openai_function_calling_tools/*"]
}
"@icon/*": [
"./src/assets/icons/*"
],
"@type/*": [
"./src/types/*"
],
"@store/*": [
"./src/store/*"
],
"@hooks/*": [
"./src/hooks/*"
],
"@constants/*": [
"./src/constants/*"
],
"@api/*": [
"./src/api/*"
],
"@components/*": [
"./src/components/*"
],
"@utils/*": [
"./src/utils/*"
],
"@src/*": [
"./src/*"
],
"@openai_function_calling_tools/*": [
"./src/openai_function_calling_tools/*"
]
},
"typeRoots": [
"./node_modules/@types",
"./src/types"
],
},
"include": ["src", "electron/index.cjs"],
"references": [{ "path": "./tsconfig.node.json" }]
}
"include": [
"src",
"electron/index.cjs"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
9 changes: 0 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,6 @@
resolved "https://registry.npmjs.org/@emotion/weak-memoize/-/weak-memoize-0.3.0.tgz"
integrity sha512-AHPmaAx+RYfZz0eYu6Gviiagpmiyw98ySSlQvCUhVGDRtDFe4DBS0x1bSjdF3gqUDYOczB+yYvBTtEylYSdRhg==

"@esbuild/[email protected]":
version "0.17.15"

"@fortawesome/[email protected]":
version "6.4.0"
resolved "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-6.4.0.tgz"
Expand Down Expand Up @@ -1270,12 +1267,6 @@
magic-string "^0.25.0"
string.prototype.matchall "^4.0.6"

"@swc/[email protected]":
version "1.3.44"

"@swc/[email protected]":
version "1.3.44"

"@swc/core@^1.3.10", "@swc/core@^1.3.35":
version "1.3.44"
optionalDependencies:
Expand Down

0 comments on commit d9f5393

Please sign in to comment.