184 lines
6.7 KiB
JavaScript
184 lines
6.7 KiB
JavaScript
"use strict";
|
||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||
return new (P || (P = Promise))(function (resolve, reject) {
|
||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||
});
|
||
};
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
exports.escape = exports.exists = exports.writeJSON = exports.readJSON = exports.mkdirp = exports.log = exports.inspect = exports.getDiscourse = exports.convert = exports.getTopics = exports.getOAvatar = exports.getFUser = exports.dOptions = exports.topicFolder = exports.findFile = exports.getReplies = exports.getPages = exports.findReplyUpload = exports.findReplyPage = exports.uploadFile = void 0;
|
||
const fs_1 = require("fs");
|
||
const util_1 = require("util");
|
||
const cwd = process.cwd();
|
||
var TurndownService = require('turndown');
|
||
const index_1 = require("./index");
|
||
const path = require("path");
|
||
const fg = require('fast-glob');
|
||
const slugify_1 = require("slugify");
|
||
var sanitize = require("sanitize-filename");
|
||
var mom = require('moment');
|
||
const uploadFile = (discourse, forum, name, filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
||
return yield discourse.upload(1, filePath);
|
||
});
|
||
exports.uploadFile = uploadFile;
|
||
const findReplyPage = (b, pages) => {
|
||
return pages.find((p) => {
|
||
return p.replies.find((r) => {
|
||
return r.replyBody == b;
|
||
});
|
||
});
|
||
};
|
||
exports.findReplyPage = findReplyPage;
|
||
const findReplyUpload = (u, page) => {
|
||
const f_pics = page.f_pics || [];
|
||
return f_pics.find((p) => {
|
||
return p.url === u;
|
||
});
|
||
};
|
||
exports.findReplyUpload = findReplyUpload;
|
||
const getPages = (topics, topic) => {
|
||
return topics.filter((t) => {
|
||
return t.title == topic.title;
|
||
});
|
||
};
|
||
exports.getPages = getPages;
|
||
const getReplies = (topics, topic) => {
|
||
if (topic.nextPages) {
|
||
const all = topics.filter((t) => {
|
||
return t.title == topic.title;
|
||
});
|
||
let replies = all.map((t) => t.replies);
|
||
replies = [].concat.apply([], replies);
|
||
replies = replies.sort((a, b) => {
|
||
const d1 = mom(a.replyDate, 'DD/MM/YYYY AT HH:mm').toDate();
|
||
const d2 = mom(b.replyDate, 'DD/MM/YYYY AT HH:mm').toDate();
|
||
return new Date(d1).getTime() > new Date(d2).getTime() ? 1 : -1;
|
||
});
|
||
return replies;
|
||
/*
|
||
const findReply = (b, pages) => {
|
||
return pages.find((p) => {
|
||
return p.replies.find((r) => {
|
||
return r.replyBody == b;
|
||
})
|
||
})
|
||
}
|
||
const p = findReply('\n\n\n<p>sounds great, let me get Old Tony´s Schaeubling 13 and a surface grinder first, after that I can do the parts for the espresso machine in the best <a href=\"https://www.youtube.com/watch?v=hpenv1ZqGx4\" rel=\"nofollow\" target=\"_blank\">maker porn fashion possible,</a> no seriously, every time I thought I know something, there’s just another video around the next corner making me cry like a baby, incl. the coffee machine <img draggable=\"false\" class=\"emoji\" alt=\"🙁\" src=\"https://s.w.org/images/core/emoji/11/svg/1f641.svg\"></p>\n', all);
|
||
debugger;
|
||
*/
|
||
}
|
||
return [];
|
||
};
|
||
exports.getReplies = getReplies;
|
||
const findFile = (folder, filename) => {
|
||
const files = fg.sync('**/**/*' + filename + '*', { dot: true, cwd: folder, absolute: true });
|
||
if (files.length == 0) {
|
||
return false;
|
||
}
|
||
return files[0];
|
||
};
|
||
exports.findFile = findFile;
|
||
const topicFolder = (forum, folder, title) => {
|
||
const _title = sanitize((0, slugify_1.default)(title));
|
||
const tf = path.resolve(forum + '/' + folder + '/' + _title);
|
||
return tf;
|
||
};
|
||
exports.topicFolder = topicFolder;
|
||
exports.dOptions = {
|
||
host: 'https://forum.osr-plastic.org',
|
||
key: 'f624b8385fb2219cb49de63d1e22883afdf7b7367a0bebf822523f49f2678031',
|
||
username: 'admin',
|
||
rateLimitConcurrency: 1
|
||
};
|
||
const getFUser = (users, user_name) => {
|
||
return users.find((u) => {
|
||
return u.name == user_name;
|
||
});
|
||
};
|
||
exports.getFUser = getFUser;
|
||
const getOAvatar = (index, user) => {
|
||
const topics = (0, exports.getTopics)(index);
|
||
let topic = topics.find((t) => {
|
||
return t.authorName == user;
|
||
});
|
||
if (topic) {
|
||
return topic.authorImage;
|
||
}
|
||
for (let i = 0; i < topics.length; i++) {
|
||
const t = topics[i];
|
||
if (t.replies) {
|
||
const r = t.replies.find((r) => {
|
||
return r.user == user;
|
||
});
|
||
if (r) {
|
||
return r.avatar;
|
||
}
|
||
}
|
||
}
|
||
return null;
|
||
};
|
||
exports.getOAvatar = getOAvatar;
|
||
const getTopics = (index) => {
|
||
let topics = [];
|
||
for (let t in index) {
|
||
topics.push(index[t]);
|
||
}
|
||
return topics;
|
||
};
|
||
exports.getTopics = getTopics;
|
||
const convert = (input) => {
|
||
var turndownService = new TurndownService();
|
||
return turndownService.turndown(input);
|
||
};
|
||
exports.convert = convert;
|
||
const getDiscourse = () => {
|
||
return new index_1.Discourser(exports.dOptions);
|
||
};
|
||
exports.getDiscourse = getDiscourse;
|
||
function inspect(arg) {
|
||
return (0, util_1.inspect)(arg, {
|
||
depth: 5,
|
||
colors: true,
|
||
});
|
||
}
|
||
exports.inspect = inspect;
|
||
function log(...args) {
|
||
console.log(...args.map((arg) => inspect(arg)));
|
||
}
|
||
exports.log = log;
|
||
function mkdirp(path) {
|
||
return __awaiter(this, void 0, void 0, function* () {
|
||
try {
|
||
yield fs_1.default.promises.mkdir(path);
|
||
}
|
||
catch (err) {
|
||
// don't care if it already exists
|
||
}
|
||
});
|
||
}
|
||
exports.mkdirp = mkdirp;
|
||
function readJSON(path) {
|
||
return __awaiter(this, void 0, void 0, function* () {
|
||
const text = yield fs_1.default.promises.readFile(path, 'utf8');
|
||
return JSON.parse(text);
|
||
});
|
||
}
|
||
exports.readJSON = readJSON;
|
||
function writeJSON(path, data) {
|
||
return fs_1.default.promises.writeFile(path, JSON.stringify(data));
|
||
}
|
||
exports.writeJSON = writeJSON;
|
||
function exists(path) {
|
||
return new Promise(function (resolve) {
|
||
fs_1.default.exists(path, resolve);
|
||
});
|
||
}
|
||
exports.exists = exists;
|
||
function escape(path) {
|
||
return path.replace(/[^\w]/g, '-').replace(/-+/, '-');
|
||
}
|
||
exports.escape = escape;
|
||
//# sourceMappingURL=util.js.map
|