mirror of
https://github.com/diced/zipline.git
synced 2025-04-11 23:31:17 -05:00
commit
7d68dc78eb
11 changed files with 50 additions and 51 deletions
18
package-lock.json
generated
18
package-lock.json
generated
|
@ -36,6 +36,14 @@
|
|||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/centra": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/centra/-/centra-2.2.0.tgz",
|
||||
"integrity": "sha512-TUpM1QoIgXa2VL1LnWbTgde39+rRnsOtvb0v8ZrX8t51g8K1Wwu4HAEXcBg5a56GV5Vm/KazyE5+g4AW8YbKNg==",
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/color-name": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
||||
|
@ -361,6 +369,11 @@
|
|||
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
|
||||
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg=="
|
||||
},
|
||||
"centra": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/centra/-/centra-2.4.2.tgz",
|
||||
"integrity": "sha512-f1RaP0V1HqVNEXfLfjNBthB2yy3KnSGnPCnOPCFLUk9e/Z4rNJ8nBaJNnghflnp88mi1IT8mfmW+HlMS1/H+bg=="
|
||||
},
|
||||
"chalk": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
|
||||
|
@ -1128,11 +1141,6 @@
|
|||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.0.0.tgz",
|
||||
"integrity": "sha512-sSHCgWfJ+Lui/u+0msF3oyCgvdkhxDbkCS6Q8uiJquzOimkJBvX6hl5aSSA7DR1XbMpdM8r7phjcF63sF4rkKg=="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
|
||||
},
|
||||
"node-pre-gyp": {
|
||||
"version": "0.15.0",
|
||||
"resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.15.0.tgz",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "typex",
|
||||
"version": "2.1.3",
|
||||
"version": "2.1.4",
|
||||
"scripts": {
|
||||
"build": "tsc -p .",
|
||||
"start": "node out/src"
|
||||
|
@ -9,12 +9,14 @@
|
|||
"@ayanaware/logger": "^2.2.1",
|
||||
"@overnightjs/core": "^1.6.15",
|
||||
"@types/bcrypt": "^3.0.0",
|
||||
"@types/centra": "^2.2.0",
|
||||
"@types/cookie-parser": "^1.4.2",
|
||||
"@types/express-session": "^1.17.0",
|
||||
"@types/mime": "^2.0.1",
|
||||
"@types/multer": "^1.4.3",
|
||||
"@types/semver": "^7.3.1",
|
||||
"bcrypt": "^5.0.0",
|
||||
"centra": "^2.4.2",
|
||||
"cookie-parser": "^1.4.5",
|
||||
"ejs": "^3.0.2",
|
||||
"express": "^4.17.1",
|
||||
|
@ -22,7 +24,6 @@
|
|||
"http-status-codes": "^1.4.0",
|
||||
"mime": "^2.4.4",
|
||||
"multer": "^1.4.2",
|
||||
"node-fetch": "^2.6.1",
|
||||
"semver": "^7.3.2",
|
||||
"spectre.css": "^0.5.8",
|
||||
"typeorm": "^0.2.24"
|
||||
|
|
|
@ -4,7 +4,6 @@ import { Request, Response } from 'express';
|
|||
import { ORMHandler } from '..';
|
||||
import { randomId, getImage, findFile, getShorten, hashPassword } from '../util';
|
||||
import { createReadStream, createWriteStream, unlinkSync, existsSync, mkdirSync, readFileSync } from 'fs'
|
||||
import { getExtension } from 'mime';
|
||||
import { User } from '../entities/User';
|
||||
import { sep } from 'path';
|
||||
import { cookiesForAPI } from '../middleware/cookiesForAPI';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Column, Entity, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
@Entity()
|
||||
export class Image {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Column, Entity, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
@Entity()
|
||||
export class Note {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Column, Entity, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
@Entity()
|
||||
export class Shorten {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Column, Entity, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { randomId, findFile } from "../util";
|
||||
import Logger from "@ayanaware/logger";
|
||||
import { readFileSync } from 'fs';
|
||||
|
|
|
@ -2,8 +2,7 @@ import "./core/Console";
|
|||
import {
|
||||
Repository,
|
||||
Connection,
|
||||
createConnection,
|
||||
ConnectionOptions
|
||||
createConnection
|
||||
} from "typeorm";
|
||||
import { User } from "./entities/User";
|
||||
import { ZiplineServer } from "./server";
|
||||
|
@ -17,7 +16,6 @@ import { notes } from "./interval";
|
|||
import { GitHub } from "./structures/GitHub";
|
||||
import { compare, } from 'semver';
|
||||
import chalk from 'chalk';
|
||||
import { execFileSync } from 'child_process';
|
||||
|
||||
if (!findFile('config.json', process.cwd())) {
|
||||
Logger.get('FS').error(`No config.json exists in ${__dirname}, exiting...`)
|
||||
|
@ -59,6 +57,7 @@ const pk = JSON.parse(readFileSync(findFile('package.json', process.cwd()), 'utf
|
|||
note: connection.getRepository(Note)
|
||||
},
|
||||
};
|
||||
|
||||
if (orm.connection.isConnected)
|
||||
Logger.get(Connection).info(
|
||||
`Successfully initialized database type: ${config.database.type}`
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import * as bodyParser from "body-parser";
|
||||
import { Server } from "@overnightjs/core";
|
||||
import { Connection } from "typeorm";
|
||||
import { ORMHandler } from ".";
|
||||
import Logger from "@ayanaware/logger";
|
||||
import * as express from "express";
|
||||
|
@ -12,7 +11,6 @@ import cookies from "cookie-parser";
|
|||
import { APIController } from "./controllers/APIController";
|
||||
import { IndexController } from "./controllers/IndexController";
|
||||
import { findFile } from "./util";
|
||||
import { ImageUtil } from "./structures/ImageUtil";
|
||||
|
||||
if (!findFile('config.json', process.cwd())) {
|
||||
Logger.get('FS').error(`No config.json exists in the ${__dirname}, exiting...`)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import fetch from 'node-fetch';
|
||||
import req from 'centra';
|
||||
import { User } from '../entities/User';
|
||||
import { Shorten } from '../entities/Shorten';
|
||||
import { Imaged } from './ImageUtil';
|
||||
|
@ -11,44 +11,38 @@ export class DiscordWebhook {
|
|||
this.checkExists();
|
||||
}
|
||||
async checkExists(): Promise<boolean> {
|
||||
const json = await (await fetch(this.url)).json();
|
||||
const json = await (await req(this.url).send()).json();
|
||||
if (json.code === 10015) throw new Error('Unknown Webhook')
|
||||
else if (json.code === 50027) throw new Error('Invalid Webhook Token')
|
||||
else if (json.code) throw new Error(`DiscordAPIError[${json.code}]: ${json.message}`);
|
||||
return json.code ? false : true;
|
||||
}
|
||||
async sendImageUpdate(user: User, image: Imaged, config: any) {
|
||||
try {
|
||||
await (await fetch(this.url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user: config.discordWebhook.username,
|
||||
avatar_url: config.discordWebhook.avatarURL,
|
||||
content: `New image uploaded to <${image.origin}> by ${user.username} (${user.id}). ${image.url})`
|
||||
})
|
||||
}));
|
||||
} catch (e) {
|
||||
throw new Error(`Coulndn't send webhook: ${e.message}`)
|
||||
}
|
||||
const res = await req(this.url, 'POST')
|
||||
.header({
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
.body({
|
||||
user: config.discordWebhook.username,
|
||||
avatar_url: config.discordWebhook.avatarURL,
|
||||
content: `New image uploaded to <${image.origin}> by ${user.username} (${user.id}). ${image.url})`
|
||||
})
|
||||
.send();
|
||||
|
||||
if (res.statusCode !== 200) throw new Error(`Couldn't send webhook. (Status: ${res.statusCode})`);
|
||||
}
|
||||
async sendShortenUpdate(user: User, shorten: Shorten, ex: Shortened, config: any) {
|
||||
try {
|
||||
await (await fetch(this.url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user: config.discordWebhook.username,
|
||||
avatar_url: config.discordWebhook.avatarURL,
|
||||
content: `New shortened url added to <${ex.origin}> by ${user.username} (${user.id}). <${shorten.origin}> -> <${shorten.url}>`
|
||||
})
|
||||
}));
|
||||
} catch (e) {
|
||||
throw new Error(`Coulndn't send webhook: ${e.message}`)
|
||||
}
|
||||
const res = await req(this.url, 'POST')
|
||||
.header({
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
.body({
|
||||
user: config.discordWebhook.username,
|
||||
avatar_url: config.discordWebhook.avatarURL,
|
||||
content: `New shortened url added to <${ex.origin}> by ${user.username} (${user.id}). <${shorten.origin}> -> <${shorten.url}>`
|
||||
})
|
||||
.send();
|
||||
|
||||
if (res.statusCode !== 200) throw new Error(`Couldn't send webhook. (Status: ${res.statusCode})`);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import fetch from 'node-fetch';
|
||||
import req from 'centra';
|
||||
|
||||
export class GitHub {
|
||||
public static async getFile(filePath: string) {
|
||||
const res = await fetch('https://raw.githubusercontent.com/ZiplineProject/Zipline/master/' + filePath);
|
||||
const res = await req(`https://raw.githubusercontent.com/ZiplineProject/Zipline/master/${filePath}`).send();
|
||||
return res.text();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue