Skip to content

Commit

Permalink
Use top level await
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Sep 28, 2024
1 parent 9f16c29 commit 23b890a
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions routes/cdn.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import mongodb from 'mongodb';
import express from 'express';
import gunzip from 'gunzip-maybe';
import tar from 'tar-stream';
import createError from 'http-errors';
import bucket from '../src/bucket.js';

const router = express.Router();
const HOST = process.env.CRANLIKE_MONGODB_SERVER || '127.0.0.1';
const PORT = process.env.CRANLIKE_MONGODB_PORT || 27017;
const USER = process.env.CRANLIKE_MONGODB_USERNAME || 'root';
const PASS = process.env.CRANLIKE_MONGODB_PASSWORD;
const AUTH = PASS ? (USER + ':' + PASS + "@") : "";
const URL = 'mongodb://' + AUTH + HOST + ':' + PORT;
const connection = mongodb.MongoClient.connect(URL);
let bucket;


function tar_index_files(input){
let files = [];
Expand Down Expand Up @@ -57,13 +50,6 @@ function stream_file(x){
return bucket.openDownloadStream(x['_id']);
}

//connect to database
console.log("CDN: connecting to mongo...");
connection.then(function(client) {
console.log("CDN: connected to MongoDB!");
const db = client.db('cranlike');
bucket = new mongodb.GridFSBucket(db, {bucketName: 'files'});
});

function send_from_bucket(hash, file, res){
return bucket.find({_id: hash}, {limit:1}).next().then(function(pkg){
Expand Down

0 comments on commit 23b890a

Please sign in to comment.