1
0
Fork 0

Fixed imports to work with got (required ES modules) and removed unused dependencies

This commit is contained in:
grumbulon 2022-04-03 13:22:25 -04:00
parent 3f537b106f
commit fe428565f5
6 changed files with 352 additions and 3684 deletions

3969
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,13 @@
{
"dependencies": {
"express": "^4.17.3",
"node": "^17.7.2",
"pug": "^3.0.2",
"request": "^2.81.0",
"serve-static": "^1.15.0"
"got": "^12.0.3",
"node": "^17.7.2"
},
"name": "abuseapi",
"name": "waifurudor.de",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node ./src/index.js"
},
@ -19,10 +18,5 @@
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"connect-livereload": "^0.6.1",
"livereload": "^0.9.3",
"nodemon": "^2.0.15"
}
"description": ""
}

View file

@ -1,11 +1,11 @@
const got = require("got");
const parseConfig = require("./config");
const downloadFromBooru = require("./download");
import got from "got";
import { readConfig } from "./config.js";
import downloadFromBooru from "./download.js";
let configFile = "./config.json";
function search() {
parseConfig.readConfig(configFile, (err, config) => {
export function search() {
readConfig(configFile, (err, config) => {
if (err) {
console.log(err);
return;
@ -42,7 +42,7 @@ function search() {
}
function getPost(postID) {
parseConfig.readConfig(configFile, (err, config) => {
readConfig(configFile, (err, config) => {
if (err) {
console.log(err);
return;
@ -51,7 +51,7 @@ function getPost(postID) {
.then((response) => {
let jsonRes = JSON.parse(response.body);
(async () => {
await downloadFromBooru.downloadFromBooru(
await downloadFromBooru(
jsonRes.file_url,
"./src/public/assets/waifu.png"
);
@ -62,5 +62,3 @@ function getPost(postID) {
});
});
}
module.exports = { search };

View file

@ -1,7 +1,7 @@
const fs = require("fs");
import { readFile } from "fs";
function readConfig(configPath, callBack) {
fs.readFile(configPath, (err, configData) => {
export function readConfig(configPath, callBack) {
readFile(configPath, (err, configData) => {
if (err) {
return callBack && callBack(err);
}
@ -13,5 +13,3 @@ function readConfig(configPath, callBack) {
}
});
}
module.exports = { readConfig };

View file

@ -1,12 +1,10 @@
const fs = require("fs");
const { promisify } = require("util");
const got = require("got");
const stream = require("stream");
import got from "got";
import { createWriteStream } from "fs";
import { promisify } from "util";
import { pipeline as _pipeline } from "stream";
const pipeline = promisify(stream.pipeline);
const pipeline = promisify(_pipeline);
async function downloadFromBooru(url, filepath) {
await pipeline(got.stream(url), fs.createWriteStream(filepath));
export default async function downloadFromBooru(url, filepath) {
await pipeline(got.stream(url), createWriteStream(filepath));
}
module.exports = { downloadFromBooru };

View file

@ -1,16 +1,15 @@
const search = require("./helpers/API");
const express = require("express");
const path = require("path");
import { search } from "./helpers/API.js";
import express from "express";
const app = express();
const port = 3000;
app.use("/assets", express.static(path.join(__dirname, "/public/assets")));
app.use("/assets", express.static("src/public/assets"));
app.get("/", (req, res) => {
res.set("Cache-Control", "no-store");
main();
res.sendFile(path.join(__dirname, "/public/index.html"));
res.sendFile("src/public/index.html", { root: "." });
});
app.listen(port, () => {
@ -18,5 +17,5 @@ app.listen(port, () => {
});
function main() {
search.search();
search();
}