@@ -12,6 +12,9 @@ import logger from "./services/log";
1212import { createUser , findByEmail } from "./user/queries" ;
1313import { Apikey , User } from "@medialit/models" ;
1414import { createApiKey } from "./apikey/queries" ;
15+ import swaggerUi from "swagger-ui-express" ;
16+ import swaggerOutput from "./swagger_output.json" ;
17+
1518import { spawn } from "child_process" ;
1619import { cleanupTUSUploads } from "./tus/cleanup" ;
1720import { cleanupExpiredTempUploads } from "./media/cleanup" ;
@@ -24,30 +27,115 @@ app.set("trust proxy", process.env.ENABLE_TRUST_PROXY === "true");
2427
2528app . use ( express . json ( ) ) ;
2629
27- app . get ( "/health" , ( req , res ) => {
28- res . status ( 200 ) . json ( {
29- status : "ok" ,
30- uptime : process . uptime ( ) ,
31- } ) ;
32- } ) ;
30+ app . get (
31+ "/health" ,
32+ /*
33+ #swagger.summary = 'Status of the server',
34+ #swagger.description = 'Returns the status of the server and uptime'
35+ #swagger.responses[200] = {
36+ description: "OK",
37+ content: {
38+ "application/json": {
39+ schema: {
40+ type: "object",
41+ properties: {
42+ status: {
43+ type: "string",
44+ example: "ok",
45+ },
46+ uptime: {
47+ type: "number",
48+ example: 12.345,
49+ },
50+ },
51+ },
52+ },
53+ },
54+ }
55+ */
56+ ( req , res ) => {
57+ res . status ( 200 ) . json ( {
58+ status : "ok" ,
59+ uptime : process . uptime ( ) ,
60+ } ) ;
61+ } ,
62+ ) ;
63+
64+ app . get (
65+ "/openapi.json" ,
66+ /* #swagger.ignore = true */
67+ ( req , res ) => {
68+ res . json ( swaggerOutput ) ;
69+ } ,
70+ ) ;
71+
72+ app . use ( "/docs" , swaggerUi . serve , swaggerUi . setup ( swaggerOutput ) ) ;
3373
3474app . use ( "/settings/media" , mediaSettingsRoutes ( passport ) ) ;
3575app . use ( "/media/signature" , signatureRoutes ) ;
3676app . use ( "/media" , tusRoutes ) ;
3777app . use ( "/media" , mediaRoutes ) ;
3878
39- app . get ( "/cleanup/temp" , async ( req , res ) => {
40- await cleanupExpiredTempUploads ( ) ;
41- res . status ( 200 ) . json ( {
42- message : "Expired temp uploads cleaned up" ,
43- } ) ;
44- } ) ;
45- app . get ( "/cleanup/tus" , async ( req , res ) => {
46- await cleanupTUSUploads ( ) ;
47- res . status ( 200 ) . json ( {
48- message : "Expired tus uploads cleaned up" ,
49- } ) ;
50- } ) ;
79+ app . get (
80+ "/cleanup/temp" ,
81+ /*
82+ #swagger.tags = ['Cleanup']
83+ #swagger.summary = 'Cleanup expired temp uploads'
84+ #swagger.description = 'Cleanup expired temp uploads'
85+ #swagger.responses[200] = {
86+ description: "OK",
87+ content: {
88+ "application/json": {
89+ schema: {
90+ type: "object",
91+ properties: {
92+ message: {
93+ type: "string",
94+ example: "Expired temp uploads cleaned up",
95+ },
96+ },
97+ },
98+ },
99+ },
100+ }
101+ */
102+ async ( req , res ) => {
103+ await cleanupExpiredTempUploads ( ) ;
104+ res . status ( 200 ) . json ( {
105+ message : "Expired temp uploads cleaned up" ,
106+ } ) ;
107+ } ,
108+ ) ;
109+ app . get (
110+ "/cleanup/tus" ,
111+ /*
112+ #swagger.tags = ['Cleanup']
113+ #swagger.summary = 'Cleanup expired tus uploads'
114+ #swagger.description = 'Cleanup expired tus uploads'
115+ #swagger.responses[200] = {
116+ description: "OK",
117+ content: {
118+ "application/json": {
119+ schema: {
120+ type: "object",
121+ properties: {
122+ message: {
123+ type: "string",
124+ example: "Expired tus uploads cleaned up",
125+ },
126+ },
127+ },
128+ },
129+ },
130+ }
131+ */
132+ async ( req , res ) => {
133+ await cleanupTUSUploads ( ) ;
134+ res . status ( 200 ) . json ( {
135+ message : "Expired tus uploads cleaned up" ,
136+ } ) ;
137+ } ,
138+ ) ;
51139
52140const port = process . env . PORT || 80 ;
53141
0 commit comments