Skip to content

Commit

Permalink
Merge pull request #7 from takejohn/feature/swagger-ui
Browse files Browse the repository at this point in the history
Swagger UI (#6)
  • Loading branch information
ringo360 authored Mar 31, 2024
2 parents f3271ec + 2b8f9f7 commit 7ad0250
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Routes/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const fs = require("fs");
const path = require("path");
const express = require("express");
const swaggerUi = require("swagger-ui-express");
const YAML = require("yaml");
const router = express.Router();
const config = require("../config.js");
const send = require("send");
const filesDir = path.resolve(__dirname, "../", config.filesDir);

const swaggerDoc = YAML.parse(fs.readFileSync(path.join(__dirname, "../", "docs", "openapi.yml"), "utf8"));
router.use("/api-doc", swaggerUi.serve, swaggerUi.setup(swaggerDoc));

router.use("/api", require("./api"))

router.get('/webupload', function (req, res) {
Expand Down
184 changes: 184 additions & 0 deletions docs/openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
openapi: '3.1.0'

info:
title: SimpleCDN API
version: '0.1'

tags:
- name: API

components:
securitySchemes:
basicAuth:
type: http
scheme: basic

paths:

/api/files/{path}:
get:
description: Gets a list of files in a directory.
tags:
- API
parameters:
- name: path
description: The path to the directory
in: path
required: false
schema:
type: string
responses:
200:
description: The file list.
content:
application/json:
schema:
type: array
items:
type: object
properties:
directory:
type: boolean
description: Whether the entry is a directory
file:
type: boolean
description: Whether the entry is a file
name:
type: string
description: The name of the entry
size:
type: number
description: The size of the entry in bytes
sizeStr:
type: string
description: Human-readable representation of the size
examples:
example:
value: [
{
"directory": true,
"file": false,
"name": "dir",
"size": 4096,
"sizeStr": "4.00 KB"
},
{
"directory": false,
"file": true,
"name": "example.png",
"size": 50136,
"sizeStr": "48.96 KB"
}
]
400:
description: The directory was not found.

/api/upload-discord:
post:
description: Uploads a file.
tags:
- API
parameters:
- name: private
description: Whether to hide the file from the file list
in: query
required: false
schema:
type: boolean
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
description: The file to upload
format: binary
responses:
200:
description: Succeeded to upload.
content:
application/json:
schema:
type: object
properties:
fileName:
type: string
description: The basename of the uploaded file.
examples:
example:
value: {
"fileName": "example.png"
}
400:
description: The file is not specified.
403:
description: The client IP is not trusted.
500:
description: Failed to upload.
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
enum:
- false
error:
type: string
description: Error description
examples:
example:
value: {
"success": false,
"error": Failed to Upload
}

/api/upload:
post:
description: Uploads a file with Basic authentication.
tags:
- API
security:
- basicAuth: []
parameters:
- name: path
description: The path of the directory to upload.
in: query
required: true
schema:
type: string
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
description: The file to upload
format: binary
responses:
200:
description: Succeeded to upload.
content:
application/json:
schema:
type: object
properties:
fileName:
type: string
description: The basename of the uploaded file.
examples:
example:
value: {
"fileName": "example.png"
}
400:
description: The path or file is not specified.
404:
description: The directory does not exist.
500:
description: Failed to upload.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"ip-range-check": "^0.2.0",
"passport": "^0.7.0",
"passport-http": "^0.3.0",
"passport-local": "^1.0.0"
"passport-local": "^1.0.0",
"swagger-ui-express": "^5.0.0",
"yaml": "^2.4.1"
}
}
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,18 @@ streamsearch@^1.1.0:
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==

swagger-ui-dist@>=5.0.0:
version "5.13.0"
resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-5.13.0.tgz#e7e5b77de906d2d774c320f5f9fcaa6801cd7b88"
integrity sha512-uaWhh6j18IIs5tOX0arvIBnVINAzpTXaQXkr7qAk8zoupegJVg0UU/5+S/FgsgVCnzVsJ9d7QLjIxkswEeTg0Q==

swagger-ui-express@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/swagger-ui-express/-/swagger-ui-express-5.0.0.tgz#7a00a18dd909574cb0d628574a299b9ba53d4d49"
integrity sha512-tsU9tODVvhyfkNSvf03E6FAk+z+5cU3lXAzMy6Pv4av2Gt2xA0++fogwC4qo19XuFf6hdxevPuVCSKFuMHJhFA==
dependencies:
swagger-ui-dist ">=5.0.0"

toidentifier@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35"
Expand Down Expand Up @@ -511,3 +523,8 @@ vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==

yaml@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.4.1.tgz#2e57e0b5e995292c25c75d2658f0664765210eed"
integrity sha512-pIXzoImaqmfOrL7teGUBt/T7ZDnyeGBWyXQBvOVhLkWLN37GXv8NMLK406UY6dS51JfcQHsmcW5cJ441bHg6Lg==

0 comments on commit 7ad0250

Please sign in to comment.