projects.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. 'use strict'
  2. const Blob = require('overleaf-editor-core').Blob
  3. exports.paths = {
  4. '/projects': {
  5. post: {
  6. 'x-swagger-router-controller': 'projects',
  7. operationId: 'initializeProject',
  8. tags: ['Project'],
  9. description: 'Initialize project.',
  10. consumes: ['application/json'],
  11. parameters: [
  12. {
  13. name: 'body',
  14. in: 'body',
  15. schema: {
  16. type: 'object',
  17. properties: {
  18. projectId: { type: 'string' },
  19. },
  20. },
  21. },
  22. ],
  23. responses: {
  24. 200: {
  25. description: 'Initialized',
  26. schema: {
  27. $ref: '#/definitions/Project',
  28. },
  29. },
  30. },
  31. security: [
  32. {
  33. basic: [],
  34. },
  35. ],
  36. },
  37. },
  38. '/projects/{project_id}': {
  39. delete: {
  40. 'x-swagger-router-controller': 'projects',
  41. operationId: 'deleteProject',
  42. tags: ['Project'],
  43. description: "Delete a project's history",
  44. parameters: [
  45. {
  46. name: 'project_id',
  47. in: 'path',
  48. description: 'project id',
  49. required: true,
  50. type: 'string',
  51. },
  52. ],
  53. responses: {
  54. 204: {
  55. description: 'Success',
  56. },
  57. },
  58. security: [
  59. {
  60. basic: [],
  61. },
  62. ],
  63. },
  64. },
  65. '/projects/{project_id}/blobs/{hash}': {
  66. get: {
  67. 'x-swagger-router-controller': 'projects',
  68. operationId: 'getProjectBlob',
  69. tags: ['Project'],
  70. description: 'Fetch blob content by its project id and hash.',
  71. parameters: [
  72. {
  73. name: 'project_id',
  74. in: 'path',
  75. description: 'project id',
  76. required: true,
  77. type: 'string',
  78. },
  79. {
  80. name: 'hash',
  81. in: 'path',
  82. description: 'Hexadecimal SHA-1 hash',
  83. required: true,
  84. type: 'string',
  85. pattern: Blob.HEX_HASH_RX_STRING,
  86. },
  87. ],
  88. produces: ['application/octet-stream'],
  89. responses: {
  90. 200: {
  91. description: 'Success',
  92. schema: {
  93. type: 'file',
  94. },
  95. },
  96. 404: {
  97. description: 'Not Found',
  98. schema: {
  99. $ref: '#/definitions/Error',
  100. },
  101. },
  102. },
  103. security: [{ jwt: [] }, { token: [] }],
  104. },
  105. put: {
  106. 'x-swagger-router-controller': 'projects',
  107. operationId: 'createProjectBlob',
  108. tags: ['Project'],
  109. description:
  110. 'Create blob to be used in a file addition operation when importing a' +
  111. ' snapshot or changes',
  112. parameters: [
  113. {
  114. name: 'project_id',
  115. in: 'path',
  116. description: 'project id',
  117. required: true,
  118. type: 'string',
  119. },
  120. {
  121. name: 'hash',
  122. in: 'path',
  123. description: 'Hexadecimal SHA-1 hash',
  124. required: true,
  125. type: 'string',
  126. pattern: Blob.HEX_HASH_RX_STRING,
  127. },
  128. ],
  129. responses: {
  130. 201: {
  131. description: 'Created',
  132. },
  133. },
  134. },
  135. },
  136. '/projects/{project_id}/latest/content': {
  137. get: {
  138. 'x-swagger-router-controller': 'projects',
  139. operationId: 'getLatestContent',
  140. tags: ['Project'],
  141. description:
  142. 'Get full content of the latest version. Text file ' +
  143. 'content is included, but binary files are just linked by hash.',
  144. parameters: [
  145. {
  146. name: 'project_id',
  147. in: 'path',
  148. description: 'project id',
  149. required: true,
  150. type: 'string',
  151. },
  152. ],
  153. responses: {
  154. 200: {
  155. description: 'Success',
  156. schema: {
  157. $ref: '#/definitions/Snapshot',
  158. },
  159. },
  160. 404: {
  161. description: 'Not Found',
  162. schema: {
  163. $ref: '#/definitions/Error',
  164. },
  165. },
  166. },
  167. },
  168. },
  169. '/projects/{project_id}/latest/hashed_content': {
  170. get: {
  171. 'x-swagger-router-controller': 'projects',
  172. operationId: 'getLatestHashedContent',
  173. tags: ['Project'],
  174. description:
  175. 'Get a snapshot of a project at the latest version ' +
  176. 'with the hashes for the contents each file',
  177. parameters: [
  178. {
  179. name: 'project_id',
  180. in: 'path',
  181. description: 'project id',
  182. required: true,
  183. type: 'string',
  184. },
  185. ],
  186. responses: {
  187. 200: {
  188. description: 'Success',
  189. schema: {
  190. $ref: '#/definitions/Snapshot',
  191. },
  192. },
  193. 404: {
  194. description: 'Not Found',
  195. schema: {
  196. $ref: '#/definitions/Error',
  197. },
  198. },
  199. },
  200. security: [
  201. {
  202. basic: [],
  203. },
  204. ],
  205. },
  206. },
  207. '/projects/{project_id}/latest/history': {
  208. get: {
  209. 'x-swagger-router-controller': 'projects',
  210. operationId: 'getLatestHistory',
  211. tags: ['Project'],
  212. description:
  213. 'Get the latest sequence of changes.' +
  214. ' TODO probably want a configurable depth.',
  215. parameters: [
  216. {
  217. name: 'project_id',
  218. in: 'path',
  219. description: 'project id',
  220. required: true,
  221. type: 'string',
  222. },
  223. ],
  224. responses: {
  225. 200: {
  226. description: 'Success',
  227. schema: {
  228. $ref: '#/definitions/ChunkResponse',
  229. },
  230. },
  231. 404: {
  232. description: 'Not Found',
  233. schema: {
  234. $ref: '#/definitions/Error',
  235. },
  236. },
  237. },
  238. },
  239. },
  240. '/projects/{project_id}/latest/persistedHistory': {
  241. get: {
  242. 'x-swagger-router-controller': 'projects',
  243. operationId: 'getLatestPersistedHistory',
  244. tags: ['Project'],
  245. description: 'Get the latest sequence of changes.',
  246. parameters: [
  247. {
  248. name: 'project_id',
  249. in: 'path',
  250. description: 'project id',
  251. required: true,
  252. type: 'string',
  253. },
  254. ],
  255. responses: {
  256. 200: {
  257. description: 'Success',
  258. schema: {
  259. $ref: '#/definitions/ChunkResponse',
  260. },
  261. },
  262. 404: {
  263. description: 'Not Found',
  264. schema: {
  265. $ref: '#/definitions/Error',
  266. },
  267. },
  268. },
  269. },
  270. },
  271. '/projects/{project_id}/versions/{version}/history': {
  272. get: {
  273. 'x-swagger-router-controller': 'projects',
  274. operationId: 'getHistory',
  275. tags: ['Project'],
  276. description:
  277. 'Get the sequence of changes that includes the given version.',
  278. parameters: [
  279. {
  280. name: 'project_id',
  281. in: 'path',
  282. description: 'project id',
  283. required: true,
  284. type: 'string',
  285. },
  286. {
  287. name: 'version',
  288. in: 'path',
  289. description: 'numeric version',
  290. required: true,
  291. type: 'number',
  292. },
  293. ],
  294. responses: {
  295. 200: {
  296. description: 'Success',
  297. schema: {
  298. $ref: '#/definitions/ChunkResponse',
  299. },
  300. },
  301. 404: {
  302. description: 'Not Found',
  303. schema: {
  304. $ref: '#/definitions/Error',
  305. },
  306. },
  307. },
  308. },
  309. },
  310. '/projects/{project_id}/versions/{version}/content': {
  311. get: {
  312. 'x-swagger-router-controller': 'projects',
  313. operationId: 'getContentAtVersion',
  314. tags: ['Project'],
  315. description: 'Get full content at the given version',
  316. parameters: [
  317. {
  318. name: 'project_id',
  319. in: 'path',
  320. description: 'project id',
  321. required: true,
  322. type: 'string',
  323. },
  324. {
  325. name: 'version',
  326. in: 'path',
  327. description: 'numeric version',
  328. required: true,
  329. type: 'number',
  330. },
  331. ],
  332. responses: {
  333. 200: {
  334. description: 'Success',
  335. schema: {
  336. $ref: '#/definitions/Snapshot',
  337. },
  338. },
  339. 404: {
  340. description: 'Not Found',
  341. schema: {
  342. $ref: '#/definitions/Error',
  343. },
  344. },
  345. },
  346. },
  347. },
  348. '/projects/{project_id}/timestamp/{timestamp}/history': {
  349. get: {
  350. 'x-swagger-router-controller': 'projects',
  351. operationId: 'getHistoryBefore',
  352. tags: ['Project'],
  353. description:
  354. 'Get the sequence of changes. ' + ' before the given timestamp',
  355. parameters: [
  356. {
  357. name: 'project_id',
  358. in: 'path',
  359. description: 'project id',
  360. required: true,
  361. type: 'string',
  362. },
  363. {
  364. name: 'timestamp',
  365. in: 'path',
  366. description: 'timestamp',
  367. required: true,
  368. type: 'string',
  369. format: 'date-time',
  370. },
  371. ],
  372. responses: {
  373. 200: {
  374. description: 'Success',
  375. schema: {
  376. $ref: '#/definitions/ChunkResponse',
  377. },
  378. },
  379. 404: {
  380. description: 'Not Found',
  381. schema: {
  382. $ref: '#/definitions/Error',
  383. },
  384. },
  385. },
  386. },
  387. },
  388. '/projects/{project_id}/version/{version}/zip': {
  389. get: {
  390. 'x-swagger-router-controller': 'projects',
  391. operationId: 'getZip',
  392. tags: ['Project'],
  393. description: 'Download zip with project content',
  394. parameters: [
  395. {
  396. name: 'project_id',
  397. in: 'path',
  398. description: 'project id',
  399. required: true,
  400. type: 'string',
  401. },
  402. {
  403. name: 'version',
  404. in: 'path',
  405. description: 'numeric version',
  406. required: true,
  407. type: 'number',
  408. },
  409. ],
  410. produces: ['application/octet-stream'],
  411. responses: {
  412. 200: {
  413. description: 'success',
  414. },
  415. 404: {
  416. description: 'not found',
  417. },
  418. },
  419. security: [
  420. {
  421. token: [],
  422. },
  423. ],
  424. },
  425. post: {
  426. 'x-swagger-router-controller': 'projects',
  427. operationId: 'createZip',
  428. tags: ['Project'],
  429. description:
  430. 'Create a zip file with project content. Returns a link to be polled.',
  431. parameters: [
  432. {
  433. name: 'project_id',
  434. in: 'path',
  435. description: 'project id',
  436. required: true,
  437. type: 'string',
  438. },
  439. {
  440. name: 'version',
  441. in: 'path',
  442. description: 'numeric version',
  443. required: true,
  444. type: 'number',
  445. },
  446. ],
  447. responses: {
  448. 200: {
  449. description: 'success',
  450. schema: {
  451. $ref: '#/definitions/ZipInfo',
  452. },
  453. },
  454. 404: {
  455. description: 'not found',
  456. },
  457. },
  458. security: [
  459. {
  460. basic: [],
  461. },
  462. ],
  463. },
  464. },
  465. }