tweaking backend, considering arch...
parent
6ed041d22e
commit
8b9e437134
@ -1,30 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "monero-lws-backend",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"engines": {
|
|
||||||
"node": "16.x"
|
|
||||||
},
|
|
||||||
"description": "",
|
|
||||||
"main": "serve.ts",
|
|
||||||
"scripts": {
|
|
||||||
"serve": "node --max_old_space_size=128 --optimize_for_size src/server.js",
|
|
||||||
"start": "concurrently npm:scrape npm:serve --restart-tries -1 --restart-after 5000",
|
|
||||||
"stop": "pkill -e -f concurrently && pkill -e -f scrape",
|
|
||||||
"scrape": "node --max_old_space_size=128 --optimize_for_size src/scraper.js",
|
|
||||||
"resync": "echo Deleting data in 5 seconds... && sleep 5 && rm storage/*.txt",
|
|
||||||
"wipe": "echo Deleting data in 5 seconds... && sleep 5 && npm run resync && storage/*.db"
|
|
||||||
},
|
|
||||||
"author": "lza_menace",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"better-sqlite3": "^7.4.5",
|
|
||||||
"bignumber.js": "^9.0.1",
|
|
||||||
"concurrently": "^6.5.0",
|
|
||||||
"dotenv": "^10.0.0",
|
|
||||||
"ethers": "^5.6.9",
|
|
||||||
"express": "^4.17.1",
|
|
||||||
"node-fetch": "^3.2.9",
|
|
||||||
"sqlite3": "^5.0.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,79 +1,44 @@
|
|||||||
|
require('dotenv').config()
|
||||||
|
|
||||||
import { Request, Response, NextFunction } from 'express';
|
import { Request, Response, NextFunction } from 'express';
|
||||||
import axios, { AxiosResponse } from 'axios';
|
import axios, { Axios, AxiosResponse } from 'axios';
|
||||||
|
|
||||||
interface Post {
|
const LWS_URL = process.env.LWS_URL ?? "http://127.0.0.1:8080";
|
||||||
userId: Number;
|
const LWS_ADMIN_URL = process.env.LWS_ADMIN_URL ?? "http://127.0.0.1:8081";
|
||||||
id: Number;
|
|
||||||
title: String;
|
|
||||||
body: String;
|
|
||||||
}
|
|
||||||
|
|
||||||
// getting all posts
|
// interface Auth {
|
||||||
const getPosts = async (req: Request, res: Response, next: NextFunction) => {
|
// auth: String;
|
||||||
// get some posts
|
// }
|
||||||
let result: AxiosResponse = await axios.get(`https://jsonplaceholder.typicode.com/posts`);
|
|
||||||
let posts: [Post] = result.data;
|
|
||||||
return res.status(200).json({
|
|
||||||
message: posts
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// getting a single post
|
// accept_requests: {"type": "import"|"create", "addresses":[...]}
|
||||||
const getPost = async (req: Request, res: Response, next: NextFunction) => {
|
// add_account: {"address": ..., "key": ...}
|
||||||
// get the post id from the req
|
// list_accounts: {}
|
||||||
let id: string = req.params.id;
|
// list_requests: {}
|
||||||
// get the post
|
// modify_account_status: {"status": "active"|"hidden"|"inactive", "addresses":[...]}
|
||||||
let result: AxiosResponse = await axios.get(`https://jsonplaceholder.typicode.com/posts/${id}`);
|
// reject_requests: {"type": "import"|"create", "addresses":[...]}
|
||||||
let post: Post = result.data;
|
// rescan: {"height":..., "addresses":[...]}
|
||||||
return res.status(200).json({
|
// webhook_add: {"type":"tx-confirmation", "address":"...", "url":"...", ...} with optional fields:
|
||||||
message: post
|
// token: A string to be returned when the webhook is triggered
|
||||||
});
|
// payment_id: 16 hex characters representing a unique identifier for a transaction
|
||||||
};
|
// webhook_delete
|
||||||
|
|
||||||
// updating a post
|
const listAccounts = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const updatePost = async (req: Request, res: Response, next: NextFunction) => {
|
let response: AxiosResponse = await axios.post(`${LWS_ADMIN_URL}/list_accounts`, {
|
||||||
// get the post id from the req.params
|
"auth": ""
|
||||||
let id: string = req.params.id;
|
|
||||||
// get the data from req.body
|
|
||||||
let title: string = req.body.title ?? null;
|
|
||||||
let body: string = req.body.body ?? null;
|
|
||||||
// update the post
|
|
||||||
let response: AxiosResponse = await axios.put(`https://jsonplaceholder.typicode.com/posts/${id}`, {
|
|
||||||
...(title && { title }),
|
|
||||||
...(body && { body })
|
|
||||||
});
|
});
|
||||||
// return response
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
message: response.data
|
message: response.data
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// deleting a post
|
const getAddressInfo = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const deletePost = async (req: Request, res: Response, next: NextFunction) => {
|
let response: AxiosResponse = await axios.post(`${LWS_URL}/get_address_info`, {
|
||||||
// get the post id from req.params
|
"address": "",
|
||||||
let id: string = req.params.id;
|
"view_key": ""
|
||||||
// delete the post
|
|
||||||
let response: AxiosResponse = await axios.delete(`https://jsonplaceholder.typicode.com/posts/${id}`);
|
|
||||||
// return response
|
|
||||||
return res.status(200).json({
|
|
||||||
message: 'post deleted successfully'
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
// adding a post
|
|
||||||
const addPost = async (req: Request, res: Response, next: NextFunction) => {
|
|
||||||
// get the data from req.body
|
|
||||||
let title: string = req.body.title;
|
|
||||||
let body: string = req.body.body;
|
|
||||||
// add the post
|
|
||||||
let response: AxiosResponse = await axios.post(`https://jsonplaceholder.typicode.com/posts`, {
|
|
||||||
title,
|
|
||||||
body
|
|
||||||
});
|
|
||||||
// return response
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
message: response.data
|
message: response.data
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
export default { getPosts, getPost, updatePost, deletePost, addPost };
|
export default { listAccounts, getAddressInfo };
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
/** source/routes/posts.ts */
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import controller from '../interfaces/main';
|
import controller from '../interfaces/main';
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.get('/posts', controller.getPosts);
|
router.get('/accounts', controller.listAccounts);
|
||||||
router.get('/posts/:id', controller.getPost);
|
router.get('/addressInfo', controller.getAddressInfo);
|
||||||
router.put('/posts/:id', controller.updatePost);
|
|
||||||
router.delete('/posts/:id', controller.deletePost);
|
|
||||||
router.post('/posts', controller.addPost);
|
|
||||||
|
|
||||||
export = router;
|
export = router;
|
Loading…
Reference in New Issue