Skip to content

Commit

Permalink
d
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Jan 29, 2022
1 parent 86a12a4 commit 951fa39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/handlers/deployments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as yup from 'yup';

import { AuthRequest, useAuth } from '../../auth/useAuth';
import { DB } from '../../Data';
import { Globals } from '../../util/Globals';
import { log } from '../../util/logging';

export const DeploymentRouter = Router();
Expand All @@ -29,7 +30,7 @@ const SiteQuery = yup.object({
});

const createBucket = async () => {
const request = await axios.post('http://localhost:8000/buckets', {
const request = await axios.post(Globals.SIGNALFS_HOST + '/buckets', {
validateStatus: false,
});

Expand All @@ -44,7 +45,7 @@ const uploadFile = async (bucket_name: string, path: string, file: string) => {
formData.append('file', f);

await axios.post(
'http://localhost:8000/buckets/' + bucket_name + '/put?path=' + path,
Globals.SIGNALFS_HOST + '/buckets/' + bucket_name + '/put?path=' + path,
formData,
{
headers: formData.getHeaders(),
Expand Down Expand Up @@ -101,12 +102,12 @@ DeploymentRouter.put(
) => {
const id = request.yupData.site;
const site = await DB.selectOneFrom('sites', ['site_id'], {
site_id: Long.fromString(id),
site_id: id,
});

if (!site) return '';

const { files } = request;
const { files, auth } = request;

if (!files) return '';

Expand Down Expand Up @@ -164,7 +165,7 @@ DeploymentRouter.put(
{
cid: cid,
},
{ site_id: Long.fromString(id) }
{ site_id: id }
);

// log.debug({c});
Expand All @@ -174,7 +175,7 @@ DeploymentRouter.put(
// log.debug({ file });
// }

response.send('Hello ' + request.auth.user_id + ' ' + cid);
response.send('Hello ' + auth.user_id + ' ' + cid);
// response.send('hi');
}
);
Expand Down
14 changes: 10 additions & 4 deletions src/lookup/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import { finished } from 'node:stream/promises';

import { DB } from '../Data';
import { DomainNotFound, FileNotFound } from '../presets/RejectMessages';
import { Globals } from '../util/Globals';
import { log } from '../util/logging';
import { NextHandler } from './NextHandler';

const traverseFolderUntilExists = async (bucket_name: string, path: string) => {
if (path == '/') return;

const data = await axios.get(
'http://localhost:8000/buckets/' + bucket_name + '/exists?path=' + path
Globals.SIGNALFS_HOST +
'/buckets/' +
bucket_name +
'/exists?path=' +
path
);

if (data.status == 200 && data.data.type == 'directory') return path;
Expand All @@ -22,13 +27,13 @@ const traverseFolderUntilExists = async (bucket_name: string, path: string) => {
const getFileOrIndex = async (cid: string, path: string) => {
const f = await Promise.allSettled([
axios.get(
'http://localhost:8000/buckets/' + cid + '/exists?path=' + path,
Globals.SIGNALFS_HOST + '/buckets/' + cid + '/exists?path=' + path,
{
validateStatus: (status) => true,
}
),
axios.get(
'http://localhost:8000/buckets/' + cid + '/get?path=' + path,
Globals.SIGNALFS_HOST + '/buckets/' + cid + '/get?path=' + path,
{
method: 'get',
responseType: 'stream',
Expand All @@ -55,7 +60,8 @@ const getFileOrIndex = async (cid: string, path: string) => {

log.debug('shipping index i guess ', path);
const index = await axios.get(
'http://localhost:8000/buckets/' +
Globals.SIGNALFS_HOST +
'/buckets/' +
cid +
'/get?path=' +
join(path, '.', 'index.html'),
Expand Down
3 changes: 3 additions & 0 deletions src/util/Globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const Globals = {
SIGNALFS_HOST: process.env.SIGNALFS_IP || '0.0.0.0:8000',
};

0 comments on commit 951fa39

Please sign in to comment.