Skip to content

Commit

Permalink
Config Gen disabling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Feb 8, 2024
1 parent 7bfe42f commit d899ae3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ npm start
To setup your new ShareX API and make it work with ShareX you will need to do the following:

1. Have the api running
2. In your console you will see `Config is available to be generated @ <URL>`, After going to that url you will be promoted to save a file called `ShareX-API-Config.sxcu` This file is a ShareX Custom Uploader Configuration file.
2. In your console you will see `Config is available to be generated @ <URL>/generate?key=<Generated Key>`, After going to that url you will be promoted to save a file called `ShareX-API-Config.sxcu` This file is a ShareX Custom Uploader Configuration file.
3. From there navigate to folder where you have downloaded the config file and open it with ShareX.
4. Your will be promoted if you want ot make `ShareX-Uploader` your default uploader, click yes.
5. You are now ready to use the API with ShareX.
Expand All @@ -73,3 +73,7 @@ The `key` option is the key that is used to authenticate the user when uploading
### Max File Size

The `maxFileSize` option is the maximum file size that the API will accept. This is useful for stopping people from uploading large files to your API and using up all of your server space. This is set in bytes and the default is `104857600 Bytes` (100mb) due to Cloudflare tunnel's max `free` plan only supports 100mb file size.

### Allow Config Gen

The `allowConfigGen` option that lets the user generate a ShareX config file. Once the user has generated the config it is **highly** recommended to set this to `false` to stop people from generating a config file and using your API without your permission.
3 changes: 2 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"url": "URL_OF_THE_CDN",
"nameHide": true,
"key": "API_KEY",
"maxFileSize": 104857600
"maxFileSize": 104857600,
"allowConfigGen": true
}
7 changes: 4 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { errorMessage, otherMessage, warnMessage } from './src/logger';
import { PORT, url, key, allowConfigGen } from './config.json';
import { loadEndpoints } from './src/functions';
import { PORT, url, key } from './config.json';
import { existsSync, mkdirSync } from 'fs';
import fileUpload from 'express-fileupload';
import express from 'express';
Expand All @@ -16,7 +16,7 @@ try {
app.set('views', './src/views');
app.set('view engine', 'ejs');
app.use(fileUpload());
global.generateKey = crypto.randomUUID();
global.generateKey = allowConfigGen ? crypto.randomUUID() : null;
const result = await loadEndpoints(app);
if (result !== undefined) {
otherMessage(`Loaded ${result} endpoints`);
Expand All @@ -28,7 +28,8 @@ try {
if (key === 'API_KEY') {
warnMessage('The API Key is still the default key! It is recommended to change this in the config.json file.');
}
otherMessage(`Config is available to be generated @ ${url}/config/generate?key=${global.generateKey}`);
if (global.generateKey === null) return;
otherMessage(`Config is available to be generated @ ${url}/generate?key=${global.generateKey}`);
setTimeout(() => {
if (global.generateKey === null) return;
global.generateKey = null;
Expand Down
9 changes: 5 additions & 4 deletions src/endpoints/generate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Application, Request, Response } from 'express';
import { apiMessage, errorMessage } from '../logger';
import { url, key } from '../../config.json';
import { url, key, allowConfigGen } from '../../config.json';

export default (app: Application) => {
app.get('/config/generate', async (req: Request, res: Response) => {
app.get('/generate', async (req: Request, res: Response) => {
try {
if (!allowConfigGen) return res.status(400).send({ success: false, message: 'Config generation is disabled' });
if (global.generateKey === null) {
return res.status(500).send({ success: false, message: 'You have already generated a config' });
return res.status(400).send({ success: false, message: 'You have already generated a config' });
}
const genKey = req.query.key;
if (genKey !== global.generateKey) {
Expand All @@ -22,7 +23,7 @@ export default (app: Application) => {
.send({
Version: '15.0.0',
Name: 'ShareX-Uploader',
DestinationType: 'ImageUploader',
DestinationType: 'ImageUploader, FileUploader',
RequestMethod: 'POST',
RequestURL: `${url}/save/{filename}`,
Headers: {
Expand Down

0 comments on commit d899ae3

Please sign in to comment.