Initial commit

This commit is contained in:
2022-01-21 01:00:13 +03:00
commit 20ad4adfe8
7 changed files with 18781 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/.vscode/
/node_modules/
/fs/
.env

48
getImages.js Normal file
View File

@@ -0,0 +1,48 @@
import getPosts from './getPosts.js';
import post2Svg from './post2Svg.js';
function filterPosts(posts) {
return posts.filter((post) => {
let isValid = false;
if (post.attachments) {
post.attachments.forEach((attachment) => {
isValid = isValid || attachment.type === 'photo';
})
}
return isValid;
})
}
async function getAllPosts(owner_id) {
let finished = false;
let offset = 0;
let posts = [];
while (!finished) {
const response = await getPosts(owner_id, offset);
posts = posts.concat(response.items);
if (posts.length === response.count) {
finished = true;
} else {
offset += response.items.length;
await new Promise(r => setTimeout(r, 5000));
}
}
return posts;
}
export default async function(owner_id) {
let posts = await getAllPosts(owner_id);
posts = filterPosts(posts);
let images = [];
posts.forEach((post) => {
images.push(post2Svg(post));
})
return images;
}

16
getPosts.js Normal file
View File

@@ -0,0 +1,16 @@
import axios from 'axios';
export default async function(owner_id, offset) {
const res = await axios.get('https://api.vk.com/method/wall.get', {
params: {
access_token: process.env.SERVICE_KEY,
owner_id,
offset: Number(offset),
count: 100,
filter: 'owner',
v: '5.81',
}
});
return res.data.response;
}

15
index.js Normal file
View File

@@ -0,0 +1,15 @@
import dotenv from 'dotenv';
dotenv.config();
import Rarepress from 'rarepress';
import getImages from './getImages.js';
(async () => {
const rarepress = new Rarepress();
// await rarepress.init({ network: 'mainnet' });
(await getImages(-1)).forEach((image) => {
console.log(image);
// const cid = await rarepress.fs.add()
})
})();

18669
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

17
package.json Normal file
View File

@@ -0,0 +1,17 @@
{
"name": "vk-wall-nft-collection",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"run": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.25.0",
"dotenv": "^14.2.0",
"rarepress": "^0.1.7"
}
}

12
post2Svg.js Normal file
View File

@@ -0,0 +1,12 @@
function makeSvg(image) {
image = image.replaceAll('&', '&')
return `<svg viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="white" />
<image x="50" y="50" width="900" height="900" href="${image}"/>
</svg>`;
}
export default function(post) {
return makeSvg(post.attachments[0].photo.sizes[0].url)
}