Skip to content

Commit

Permalink
Archive
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonybudd committed Jul 20, 2020
1 parent 280818c commit a9f67be
Show file tree
Hide file tree
Showing 13 changed files with 438 additions and 63 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ $ cd vipfs
$ npm install
$ npm run build
$ docker-compose up
$ npm run publish // returns 'Qmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
$ npm run publish // wait.. returns 'Qmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
$ open http://localhost:8080/ipns/Qmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ open https://gateway.ipfs.io/ipns/Qmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

## Archiving Websites
To archive a website run the following commands
```sh
$ npm run archive -- https://example.com
$ npm run build
$ npm run publish
```

## Video Tutorial
[![VIPFS Video Tutorial](https://ideea.io/static/img/vipfs-youtube-embed.png)](https://www.youtube.com/watch?v=Fq7h-cSN9i8)

Expand All @@ -48,3 +56,4 @@ VIPFS comes with a few templates to demonstrate functionality. You can easily mo
- [Video](/src/components/video.vue)
- [Gallery](/src/components/gallery.vue)
- [Payment](/src/components/payment.vue)
- [Archive](/src/components/archive.vue)
28 changes: 28 additions & 0 deletions archive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const scrape = require('website-scraper');
const moment = require('moment');
const fs = require('fs');

const archiveURL = process.argv[2];

const archiveDir = './storage/archive';
if (!fs.existsSync(archiveDir)) fs.mkdirSync(archiveDir);

const id = moment().format("YYYY-MMM-DD--HH-mm-ss");
const archivePath = archiveDir + '/' + id;

scrape({
urls: [archiveURL],
directory: archivePath,
}).then(() => {
console.log(`${archiveURL} successfully archived to ${archivePath}`);

const archiveDBPath = './src/archiveDB.json';
if (!fs.existsSync(archiveDBPath)) fs.writeFileSync(archiveDBPath, '[]');

const archiveDB = fs.readFileSync(archiveDBPath)
var archiveJson = JSON.parse(archiveDB);
if (!Array.isArray(archiveJson)) archiveJson = [];
archiveJson.unshift({ id, created_at: moment().format("YYYY-MM-DD HH:mm:ss"), url: archiveURL });
fs.writeFileSync(archiveDBPath, JSON.stringify(archiveJson));
console.log(`archiveDB.json updated`);
});
Loading

0 comments on commit a9f67be

Please sign in to comment.