This repository has been archived by the owner on Aug 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
big cock
committed
Aug 20, 2023
1 parent
9572e54
commit 59535c9
Showing
9 changed files
with
136 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
|
||
import fs from "fs"; | ||
import path from "path"; | ||
import type { Response } from "express"; | ||
|
||
export function getPath(dir: string): string { | ||
return path.resolve(process.cwd(), dir); | ||
} | ||
|
||
export function renderError(res: Response, status: number, message: string) { | ||
res.status(status).json({ | ||
error: true, | ||
status, | ||
message, | ||
}); | ||
} | ||
|
||
export function findFileWithoutExtension( | ||
fileName: string, | ||
dirPath: string | ||
): string | null { | ||
const fileWithoutExtension = fileName.replace(/\.[^.]+$/, ""); | ||
const files = fs.readdirSync(dirPath); | ||
|
||
return ( | ||
files.find( | ||
(file) => fileWithoutExtension === file.replace(/\.[^.]+$/, "") | ||
) || null | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as images from "./images"; | ||
import * as keys from "./keys"; | ||
import * as sharex from "./sharex"; | ||
|
||
export { images, keys, sharex }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use strict"; | ||
|
||
import fs from "fs"; | ||
|
||
export interface IKeys { | ||
key: string; | ||
ip: string; | ||
created_at: string; | ||
} | ||
export function loadKeysFromFile(): IKeys[] { | ||
try { | ||
const keysData = fs.readFileSync("keys.json", "utf8"); | ||
return JSON.parse(keysData) as IKeys[]; | ||
} catch (err) { | ||
console.error(`Failed to load keys: ${err}`); | ||
return []; | ||
} | ||
} | ||
|
||
export function saveKeysToFile(keys: IKeys[]): void { | ||
fs.writeFileSync("keys.json", JSON.stringify(keys, null, 2)); | ||
} | ||
|
||
export function generateRandomKey(length: number): string { | ||
const chars = | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
let result = ""; | ||
|
||
for (let i = 0; i < length; i++) { | ||
result += chars.charAt(Math.floor(Math.random() * chars.length)); | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"use strict"; | ||
|
||
import { type Response } from "express"; | ||
|
||
export interface IShareXConfig { | ||
Name: string; | ||
DestinationType: string; | ||
RequestType: string; | ||
RequestURL: string; | ||
Headers: { | ||
key: string; | ||
}; | ||
FileFormName: string; | ||
ResponseType: string; | ||
URL: string; | ||
} | ||
|
||
export function generateShareXConfig(key: string): IShareXConfig { | ||
return { | ||
Name: "Lazy Uploader", | ||
DestinationType: "ImageUploader, TextUploader, FileUploader", | ||
RequestType: "POST", | ||
RequestURL: "https://im.sleepdeprived.wtf/api/upload/", | ||
Headers: { | ||
key, | ||
}, | ||
FileFormName: "sharex", | ||
ResponseType: "Text", | ||
URL: "https://im.sleepdeprived.wtf/$json:url$", | ||
}; | ||
} | ||
|
||
export function sendShareXConfig(res: Response, config: IShareXConfig): void { | ||
const file = JSON.stringify(config, null, 2); | ||
const fileName = "sharex-config.sxcu"; | ||
|
||
res.setHeader("Content-disposition", `attachment; filename=${fileName}`); | ||
res.setHeader("Content-type", "application/json"); | ||
|
||
res.send(file); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters