140 lines
4.0 KiB
TypeScript
140 lines
4.0 KiB
TypeScript
import { Router } from 'express';
|
|
import validateSchema from '../tools/validateSchema';
|
|
import * as lc from '../controllers/linkController';
|
|
import * as ls from '../schemas/linkSchema';
|
|
import requireUser from '../middleware/requireUser';
|
|
|
|
const linkRouter = Router();
|
|
|
|
/**
|
|
* @openapi
|
|
*
|
|
* /api/v1/link/short:
|
|
* get:
|
|
* description: Generates a new short link
|
|
* tags: [Link]
|
|
* summary: Get a new short link
|
|
* parameters:
|
|
* - name: length
|
|
* in: query
|
|
* description: generated URL's length
|
|
* required: false
|
|
* schema:
|
|
* type: integer
|
|
* format: int32
|
|
* default: 9
|
|
* minimum: 2
|
|
* maximum: 127
|
|
* - name: alphanum
|
|
* in: query
|
|
* description: whether to use numbers in generated URL
|
|
* required: false
|
|
* schema:
|
|
* type: boolean
|
|
* default: true
|
|
* - name: case
|
|
* in: query
|
|
* description: whether to use uppercase ("upper"), lowercase ("lower") or mixed case (default)
|
|
* schema:
|
|
* type: string
|
|
* - name: withSubdomain
|
|
* in: query
|
|
* description: whether to generate a subdomain too (will be generated only if supported by server)
|
|
* required: false
|
|
* schema:
|
|
* type: boolean
|
|
* default: false
|
|
* produces:
|
|
* - application/json
|
|
* responses:
|
|
* 200:
|
|
* description: Link generated successfully
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/LinkResponseDTO'
|
|
* 400:
|
|
* description: Bad request
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/ErrorDTO'
|
|
*/
|
|
linkRouter.get('/api/v1/link/short', validateSchema(ls.shortLinkRequestSchema), lc.generateShortLinkHandler);
|
|
|
|
|
|
/**
|
|
* @openapi
|
|
*
|
|
* /api/v1/link/fromWordlist:
|
|
* get:
|
|
* description: Generates a new pseudosentence link from wordlist.
|
|
* tags: [Link]
|
|
* summary: Get a new "sentence" link
|
|
* parameters:
|
|
* - name: withSubdomain
|
|
* in: query
|
|
* description: whether to generate a subdomain too (will be generated only if supported by server)
|
|
* required: false
|
|
* schema:
|
|
* type: boolean
|
|
* default: false
|
|
* produces:
|
|
* - application/json
|
|
* responses:
|
|
* 200:
|
|
* description: Link generated successfully
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/LinkResponseDTO'
|
|
* 400:
|
|
* description: Bad request
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/ErrorDTO'
|
|
*/
|
|
linkRouter.get('/api/v1/link/fromWordlist', validateSchema(ls.sentenceLinkRequestSchema), lc.generateSentenceLinkHandler);
|
|
|
|
/**
|
|
* @openapi
|
|
*
|
|
* /api/v1/link/new:
|
|
* post:
|
|
* description:
|
|
* Register a new shortened URL. <br/>
|
|
* See linkSchema.ts for constraints. <br/>
|
|
* <b>Note:</b> This endpoint's functionality differs depending on the user info,
|
|
* which means guests will be treated differently from authenticated users.
|
|
* tags: [Link]
|
|
* summary: "[AUTHED?] Shorten a link"
|
|
* requestBody:
|
|
* required: true
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/CreateLinkRequestDTO'
|
|
* produces:
|
|
* - application/json
|
|
* responses:
|
|
* 200:
|
|
* description: New link created successfully
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/CreateLinkResponseDTO'
|
|
* 400:
|
|
* description: Bad request
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/ErrorDTO'
|
|
*/
|
|
linkRouter.post('/api/v1/link/new',
|
|
validateSchema(ls.createLinkRequestSchema),
|
|
lc.createLinkHandler
|
|
);
|
|
|
|
|
|
export default linkRouter; |