Skip to content

Commit

Permalink
Merge pull request #4 from NekoNyaDevs/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
TheDogHusky authored Jul 24, 2024
2 parents 19f5921 + b5d6bf8 commit 7d09e1a
Show file tree
Hide file tree
Showing 31 changed files with 1,186 additions and 404 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ src/config.ts
./src/config.ts
/src/config.ts

images/**
images/*/**
!images/README.md

package-lock.json
Expand Down
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

## 📝・Description

NekoNya Storage is NekoNya's Cloud storage system (I don't know if I can really call this a cloud..).It is a simple server that stores, runs a web server so you can access them and has an API.
Warning: This is a private server. Any use of this server for something else without our permission is prohibited.
NekoNya-Storage is a Node.JS TypeScript webserver serving NekoNya's files and running the API behind the scenes.

## 📚・How to use
If you wish to deploy your own instance of NekoNya-Storage for any reasons, you can do so by following the instructions below. But please, do not forget to give credit to the original authors of this project.

## 📚・How to deploy

### 📦・Install

Expand All @@ -19,15 +20,24 @@ $ npm install
### 📝・Configuration

Change the file `config.example.ts` to `config.ts` and change the values to your liking.
> Note: The configuration file is documented.
Change the file `src/config.example.ts` to `config.ts` and change the values to your liking. The configuration file is commented so you can easily understand what each value does.

Don't forget to add images in the categories inside of the `images` folder.

### 🚀・Run

Production:

```bash
$ npm start
```

Development:

```bash
$ npm run dev
```

## 📜・License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
This project is licensed under the GNU GPL 3.0 License - see the [LICENSE](LICENSE) file for details
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
{
"name": "nekonya-storage",
"version": "1.0.5",
"description": "The storage server of NekoNya.",
"main": "lib/index.js",
"version": "2.0.5",
"description": "The static storage server and API of NekoNya.",
"main": "src/index.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npx tsc && node lib/index.js"
"start": "cross-env NODE_ENV=production npx tsx src/index",
"dev": "cross-env NODE_ENV=development npx tsx src/index"
},
"keywords": [],
"author": "TheDogHusky",
"license": "ISC",
"license": "GPL-3.0-or-later",
"dependencies": {
"@classycrafter/super-logger": "^2.0.00",
"chalk": "^4.1.2",
"cors": "^2.8.5",
"ejs": "^3.1.8",
"cross-env": "^7.0.3",
"express": "^4.18.2",
"jose": "^4.13.1",
"node-fetch": "^2.6.9"
"express-validator": "^7.1.0",
"tsx": "^4.16.2"
},
"devDependencies": {
"typescript": "^4.9.5",
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/node-fetch": "^2.6.2"
"typescript": "^4.9.5"
}
}
5 changes: 2 additions & 3 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from 'fs';
import path from 'path';
import {Router} from 'express';
import {Logger} from "@classycrafter/super-logger";

Expand All @@ -15,8 +14,8 @@ export default (logger: Logger) => {
});

fs.readdirSync(__dirname).forEach(dir => {
if(dir === 'index.ts' || dir === "index.js") return;
const route = require('./' + dir).default;
if(dir === 'index.ts') return;
const route = require('./' + dir).default(logger);
router.use(`/${dir}/`, route);
logger.info(`Loaded API version ${dir}`, "API");
});
Expand Down
66 changes: 66 additions & 0 deletions src/api/v1/8ball.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Router } from 'express';
const router = Router();

const eightballAnswers = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes, definitely",
"You may rely on it",

"As I see it, yes",
"Most likely",
"Outlook good",
"Yes",
"Signs point to yes",

"Reply hazy try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",

"Don't count on it",
"My reply is no",
"My sources say no",
"Outlook not so good",
"Very doubtful"
];

const cuteEightballAnswers = [
"Yes!!",
"Of Cwurse!",
"Yes, definitelwy nya!",
"Without any doubts nya!",
"My tail says yess!",

"Mhh.. I think so!",
"Most likely!",
"Outwook good!",
"Yesh!",
"Signs point to yes!",

"I don't know nya..",
"Ask again later, nya!",
"Better not twell you now!",
"Cannot predict now..",
"Concentrate and ask again! :3",

"Don't count on it! >:c",
">-< My reply is nyo!",
"My sources say nyo!",
"Outlook nyot so good! :c",
"Very doubtfwul!"
];

router.get('/', (req, res) => {
const cute = req.query.cute || false;
const answers = cute ? cuteEightballAnswers : eightballAnswers;
const answer = answers[Math.floor(Math.random() * answers.length)];

res.status(200).json({
answer: answer
});
});

export default router;
67 changes: 67 additions & 0 deletions src/api/v1/endpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Router } from 'express';
const router = Router();

router.get("/", (req, res) => {
res.status(200).json([
{
"name": "random",
"description": "Get random images",
"path": "/random",
"methods": ["GET"],
"parameters": [
{
"name": "type",
"description": "Type of image",
"required": true,
"type": "string",
"values": ["neko", "kitsune", "pat", "kisse", "hug", "lewd", "slap"]
}
],
"queries": [],
"body": []
},
{
"name": "8ball",
"description": "Get a random 8ball response",
"path": "/8ball",
"methods": ["GET"],
"parameters": [],
"queries": [
{
"name": "cute",
"description": "If you want the response to be cute",
"required": false,
"type": "boolean"
}
],
"body": []
},
{
"name": "owoify",
"description": "Owoify text (make it cute)",
"path": "/owoify",
"methods": ["GET", "POST"],
"parameters": [],
"queries": [
{
"name": "text",
"description": "Text to owoify",
"required": true,
"type": "string"
}
],
"body": [
{
"name": "text",
"description": "Text to owoify",
"required": true,
"type": "string",
"max_length": 2000,
"min_length": 1
}
]
}
]);
});

export default router;
41 changes: 13 additions & 28 deletions src/api/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,26 @@
import fs from 'fs';
import path from 'path';
import {Router} from 'express';
import {isValidToken} from "../../structures/functions";
import {Logger} from "@classycrafter/super-logger";

// Load every file here in this directory except this file, then load the returned route inside a router object which is then exported
const router = Router();
router.get('/', (req, res) => {
res.status(200).json({
status: 200,
message: 'OK',
version: 'v1'
version: 'v1',
endpoints: '/endpoints'
});
});

router.use(async (req, res, next) => {
if(req.path === '/token') return next();
export default (logger: Logger) => {
const files = fs.readdirSync(__dirname).filter(file => file !== path.basename(__filename));
for (const file of files) {
const route = require('./' + file).default;
const fileName = file.replace('.ts', '');
router.use(`/${fileName}`, route);
logger.info(`Loaded route /api/v1/${fileName}`, "API");
}

await isValidToken(req).then((result) => {
if (result.status !== 200) {
return res.status(result.status).json({
status: result.status,
error: result.error,
message: result.message
});
}

next();
}).catch((err: Error) => {
next(err);
});
});

const files = fs.readdirSync(__dirname).filter(file => file !== path.basename(__filename) && file.endsWith('.js'));
for (const file of files) {
const route = require('./' + file).default;
const fileName = file.replace('.js', '');
router.use(`/${fileName}`, route);
}

export default router;
return router;
};
43 changes: 0 additions & 43 deletions src/api/v1/list.ts

This file was deleted.

Loading

0 comments on commit 7d09e1a

Please sign in to comment.