Skip to content

Commit

Permalink
[WIP] Database modeling, archiving
Browse files Browse the repository at this point in the history
  • Loading branch information
owenkellogg committed Dec 25, 2022
1 parent 5834a11 commit 99851ba
Show file tree
Hide file tree
Showing 20 changed files with 6,785 additions and 424 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ get402.json
dist/
.rabbi/config.json
keys/
downloads
.runcache
.DS_Store
56 changes: 56 additions & 0 deletions archive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

const http = require('http');
const fs = require('fs');

import { resolve } from 'path'

import { createWriteStream } from 'fs'

const axios = require('axios')

async function downloadImage () {
const url = 'https://objectstorage.us-ashburn-1.oraclecloud.com/p/bqZW7p5X2I7LZg1OqP_-UjdhDEpzbuUmD18OtwfqvBIqJW05y4bqqaZGgngAd_8t/n/fr4eeztjonbe/b/vpaas-recordings-prod-8x8-us-ashburn-1/o/vpaas-magic-cookie-30f799d005ea4007aaa7afbf1a14cdcf/waqcxosifleqyirx/sampleappworthytruthsclarifyclearly_2022-12-21-17-53-31.mp4'

const path = resolve(__dirname, 'images', 'code.jpg')
const writer = createWriteStream(path)

const response = await axios({
url,
method: 'GET',
responseType: 'stream'
})

response.data.pipe(writer)

return new Promise((resolve, reject) => {
writer.on('finish', resolve)
writer.on('error', reject)
})
}



export async function main() {

const url = 'https://objectstorage.us-ashburn-1.oraclecloud.com/p/bqZW7p5X2I7LZg1OqP_-UjdhDEpzbuUmD18OtwfqvBIqJW05y4bqqaZGgngAd_8t/n/fr4eeztjonbe/b/vpaas-recordings-prod-8x8-us-ashburn-1/o/vpaas-magic-cookie-30f799d005ea4007aaa7afbf1a14cdcf/waqcxosifleqyirx/sampleappworthytruthsclarifyclearly_2022-12-21-17-53-31.mp4'

const file = fs.createWriteStream("file.jpg");
const request = http.get(url, function(response) {
response.pipe(file);

// after download completed close filestream
file.on("finish", () => {
file.close();
console.log("Download Completed");
});
});


}

if (require.main === module) {

downloadImage()

//main()
}
Empty file added archive.ts#
Empty file.
66 changes: 66 additions & 0 deletions download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

const Downloader = require("nodejs-file-downloader");

const S3 = require('aws-sdk').S3

const S3S = require('s3-streams');

import { createReadStream } from "fs";

(async () => {
//Wrapping the code with an async function, just for the sake of example.
//
const url = 'https://objectstorage.us-ashburn-1.oraclecloud.com/p/bqZW7p5X2I7LZg1OqP_-UjdhDEpzbuUmD18OtwfqvBIqJW05y4bqqaZGgngAd_8t/n/fr4eeztjonbe/b/vpaas-recordings-prod-8x8-us-ashburn-1/o/vpaas-magic-cookie-30f799d005ea4007aaa7afbf1a14cdcf/waqcxosifleqyirx/sampleappworthytruthsclarifyclearly_2022-12-21-17-53-31.mp4'

const downloader = new Downloader({
url,
directory: "./downloads", //This folder will be created, if it doesn't exist.
onProgress: function (percentage, chunk, remainingSize) {
//Gets called with each chunk.
console.log("% ", percentage);
console.log("Current chunk of data: ", chunk);
console.log("Remaining bytes: ", remainingSize);
},
});




try {
const {filePath,downloadStatus} = await downloader.download(); //Downloader.download() resolves with some useful properties.

var upload = S3S.WriteStream(new S3(), {
Bucket: 'pow.co',
Key: 'powco_recordings/my-key'
});

createReadStream(filePath).pipe(upload);

var s3 = new S3();

//configuring parameters
var params = {
Bucket: 'pow.co',
Body : createReadStream(filepath),
Key : "powco_recordings/"+Date.now()+"_"+path.basename(filepath)
};

s3.upload(params, function (err, data) {
//handle error
if (err) {
console.log("Error", err);
}

//success
if (data) {
console.log("Uploaded in:", data.Location);
}
});

console.log("All done", {filePath});
} catch (error) {
//IMPORTANT: Handle a possible error. An error is thrown in case of network errors, or status codes of 400 and above.
//Note that if the maxAttempts is set to higher than 1, the error is thrown only if all attempts fail.
console.log("Download failed", error);
}
})();
Empty file added file.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 99851ba

Please sign in to comment.