projects.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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. name: 'range',
  89. in: 'header',
  90. description: 'HTTP Range header',
  91. required: false,
  92. type: 'string',
  93. },
  94. ],
  95. produces: ['application/octet-stream'],
  96. responses: {
  97. 200: {
  98. description: 'Success',
  99. schema: {
  100. type: 'file',
  101. },
  102. },
  103. 404: {
  104. description: 'Not Found',
  105. schema: {
  106. $ref: '#/definitions/Error',
  107. },
  108. },
  109. },
  110. security: [{ jwt: [] }, { token: [] }],
  111. },
  112. head: {
  113. 'x-swagger-router-controller': 'projects',
  114. operationId: 'headProjectBlob',
  115. tags: ['Project'],
  116. description: 'Fetch blob content-length by its project id and hash.',
  117. parameters: [
  118. {
  119. name: 'project_id',
  120. in: 'path',
  121. description: 'project id',
  122. required: true,
  123. type: 'string',
  124. },
  125. {
  126. name: 'hash',
  127. in: 'path',
  128. description: 'Hexadecimal SHA-1 hash',
  129. required: true,
  130. type: 'string',
  131. pattern: Blob.HEX_HASH_RX_STRING,
  132. },
  133. ],
  134. produces: ['application/octet-stream'],
  135. responses: {
  136. 200: {
  137. description: 'Success',
  138. schema: {
  139. type: 'file',
  140. },
  141. },
  142. 404: {
  143. description: 'Not Found',
  144. schema: {
  145. $ref: '#/definitions/Error',
  146. },
  147. },
  148. },
  149. security: [{ jwt: [] }, { token: [] }],
  150. },
  151. put: {
  152. 'x-swagger-router-controller': 'projects',
  153. operationId: 'createProjectBlob',
  154. tags: ['Project'],
  155. description:
  156. 'Create blob to be used in a file addition operation when importing a' +
  157. ' snapshot or changes',
  158. parameters: [
  159. {
  160. name: 'project_id',
  161. in: 'path',
  162. description: 'project id',
  163. required: true,
  164. type: 'string',
  165. },
  166. {
  167. name: 'hash',
  168. in: 'path',
  169. description: 'Hexadecimal SHA-1 hash',
  170. required: true,
  171. type: 'string',
  172. pattern: Blob.HEX_HASH_RX_STRING,
  173. },
  174. ],
  175. responses: {
  176. 201: {
  177. description: 'Created',
  178. },
  179. },
  180. },
  181. post: {
  182. 'x-swagger-router-controller': 'projects',
  183. operationId: 'copyProjectBlob',
  184. tags: ['Project'],
  185. description:
  186. 'Copies a blob from a source project to a target project when duplicating a project',
  187. parameters: [
  188. {
  189. name: 'project_id',
  190. in: 'path',
  191. description: 'target project id',
  192. required: true,
  193. type: 'string',
  194. },
  195. {
  196. name: 'hash',
  197. in: 'path',
  198. description: 'Hexadecimal SHA-1 hash',
  199. required: true,
  200. type: 'string',
  201. pattern: Blob.HEX_HASH_RX_STRING,
  202. },
  203. {
  204. name: 'copyFrom',
  205. in: 'query',
  206. description: 'source project id',
  207. required: true,
  208. type: 'string',
  209. },
  210. ],
  211. responses: {
  212. 201: {
  213. description: 'Created',
  214. },
  215. },
  216. },
  217. },
  218. '/projects/{project_id}/latest/content': {
  219. get: {
  220. 'x-swagger-router-controller': 'projects',
  221. operationId: 'getLatestContent',
  222. tags: ['Project'],
  223. description:
  224. 'Get full content of the latest version. Text file ' +
  225. 'content is included, but binary files are just linked by hash.',
  226. parameters: [
  227. {
  228. name: 'project_id',
  229. in: 'path',
  230. description: 'project id',
  231. required: true,
  232. type: 'string',
  233. },
  234. ],
  235. responses: {
  236. 200: {
  237. description: 'Success',
  238. schema: {
  239. $ref: '#/definitions/Snapshot',
  240. },
  241. },
  242. 404: {
  243. description: 'Not Found',
  244. schema: {
  245. $ref: '#/definitions/Error',
  246. },
  247. },
  248. },
  249. },
  250. },
  251. '/projects/{project_id}/latest/hashed_content': {
  252. get: {
  253. 'x-swagger-router-controller': 'projects',
  254. operationId: 'getLatestHashedContent',
  255. tags: ['Project'],
  256. description:
  257. 'Get a snapshot of a project at the latest version ' +
  258. 'with the hashes for the contents each file',
  259. parameters: [
  260. {
  261. name: 'project_id',
  262. in: 'path',
  263. description: 'project id',
  264. required: true,
  265. type: 'string',
  266. },
  267. ],
  268. responses: {
  269. 200: {
  270. description: 'Success',
  271. schema: {
  272. $ref: '#/definitions/Snapshot',
  273. },
  274. },
  275. 404: {
  276. description: 'Not Found',
  277. schema: {
  278. $ref: '#/definitions/Error',
  279. },
  280. },
  281. },
  282. security: [
  283. {
  284. basic: [],
  285. },
  286. ],
  287. },
  288. },
  289. '/projects/{project_id}/latest/history': {
  290. get: {
  291. 'x-swagger-router-controller': 'projects',
  292. operationId: 'getLatestHistory',
  293. tags: ['Project'],
  294. description:
  295. 'Get the latest sequence of changes.' +
  296. ' TODO probably want a configurable depth.',
  297. parameters: [
  298. {
  299. name: 'project_id',
  300. in: 'path',
  301. description: 'project id',
  302. required: true,
  303. type: 'string',
  304. },
  305. ],
  306. responses: {
  307. 200: {
  308. description: 'Success',
  309. schema: {
  310. $ref: '#/definitions/ChunkResponse',
  311. },
  312. },
  313. 404: {
  314. description: 'Not Found',
  315. schema: {
  316. $ref: '#/definitions/Error',
  317. },
  318. },
  319. },
  320. },
  321. },
  322. '/projects/{project_id}/latest/history/raw': {
  323. get: {
  324. 'x-swagger-router-controller': 'projects',
  325. operationId: 'getLatestHistoryRaw',
  326. tags: ['Project'],
  327. description: 'Get the metadata of latest sequence of changes.',
  328. parameters: [
  329. {
  330. name: 'project_id',
  331. in: 'path',
  332. description: 'project id',
  333. required: true,
  334. type: 'string',
  335. },
  336. ],
  337. responses: {
  338. 200: {
  339. description: 'Success',
  340. schema: {
  341. $ref: '#/definitions/ChunkResponseRaw',
  342. },
  343. },
  344. 404: {
  345. description: 'Not Found',
  346. schema: {
  347. $ref: '#/definitions/Error',
  348. },
  349. },
  350. },
  351. },
  352. },
  353. '/projects/{project_id}/latest/persistedHistory': {
  354. get: {
  355. 'x-swagger-router-controller': 'projects',
  356. operationId: 'getLatestPersistedHistory',
  357. tags: ['Project'],
  358. description: 'Get the latest sequence of changes.',
  359. parameters: [
  360. {
  361. name: 'project_id',
  362. in: 'path',
  363. description: 'project id',
  364. required: true,
  365. type: 'string',
  366. },
  367. ],
  368. responses: {
  369. 200: {
  370. description: 'Success',
  371. schema: {
  372. $ref: '#/definitions/ChunkResponse',
  373. },
  374. },
  375. 404: {
  376. description: 'Not Found',
  377. schema: {
  378. $ref: '#/definitions/Error',
  379. },
  380. },
  381. },
  382. },
  383. },
  384. '/projects/{project_id}/versions/{version}/history': {
  385. get: {
  386. 'x-swagger-router-controller': 'projects',
  387. operationId: 'getHistory',
  388. tags: ['Project'],
  389. description:
  390. 'Get the sequence of changes that includes the given version.',
  391. parameters: [
  392. {
  393. name: 'project_id',
  394. in: 'path',
  395. description: 'project id',
  396. required: true,
  397. type: 'string',
  398. },
  399. {
  400. name: 'version',
  401. in: 'path',
  402. description: 'numeric version',
  403. required: true,
  404. type: 'number',
  405. },
  406. ],
  407. responses: {
  408. 200: {
  409. description: 'Success',
  410. schema: {
  411. $ref: '#/definitions/ChunkResponse',
  412. },
  413. },
  414. 404: {
  415. description: 'Not Found',
  416. schema: {
  417. $ref: '#/definitions/Error',
  418. },
  419. },
  420. },
  421. },
  422. },
  423. '/projects/{project_id}/versions/{version}/content': {
  424. get: {
  425. 'x-swagger-router-controller': 'projects',
  426. operationId: 'getContentAtVersion',
  427. tags: ['Project'],
  428. description: 'Get full content at the given version',
  429. parameters: [
  430. {
  431. name: 'project_id',
  432. in: 'path',
  433. description: 'project id',
  434. required: true,
  435. type: 'string',
  436. },
  437. {
  438. name: 'version',
  439. in: 'path',
  440. description: 'numeric version',
  441. required: true,
  442. type: 'number',
  443. },
  444. ],
  445. responses: {
  446. 200: {
  447. description: 'Success',
  448. schema: {
  449. $ref: '#/definitions/Snapshot',
  450. },
  451. },
  452. 404: {
  453. description: 'Not Found',
  454. schema: {
  455. $ref: '#/definitions/Error',
  456. },
  457. },
  458. },
  459. },
  460. },
  461. '/projects/{project_id}/timestamp/{timestamp}/history': {
  462. get: {
  463. 'x-swagger-router-controller': 'projects',
  464. operationId: 'getHistoryBefore',
  465. tags: ['Project'],
  466. description:
  467. 'Get the sequence of changes. ' + ' before the given timestamp',
  468. parameters: [
  469. {
  470. name: 'project_id',
  471. in: 'path',
  472. description: 'project id',
  473. required: true,
  474. type: 'string',
  475. },
  476. {
  477. name: 'timestamp',
  478. in: 'path',
  479. description: 'timestamp',
  480. required: true,
  481. type: 'string',
  482. format: 'date-time',
  483. },
  484. ],
  485. responses: {
  486. 200: {
  487. description: 'Success',
  488. schema: {
  489. $ref: '#/definitions/ChunkResponse',
  490. },
  491. },
  492. 404: {
  493. description: 'Not Found',
  494. schema: {
  495. $ref: '#/definitions/Error',
  496. },
  497. },
  498. },
  499. },
  500. },
  501. '/projects/{project_id}/version/{version}/zip': {
  502. get: {
  503. 'x-swagger-router-controller': 'projects',
  504. operationId: 'getZip',
  505. tags: ['Project'],
  506. description: 'Download zip with project content',
  507. parameters: [
  508. {
  509. name: 'project_id',
  510. in: 'path',
  511. description: 'project id',
  512. required: true,
  513. type: 'string',
  514. },
  515. {
  516. name: 'version',
  517. in: 'path',
  518. description: 'numeric version',
  519. required: true,
  520. type: 'number',
  521. },
  522. ],
  523. produces: ['application/octet-stream'],
  524. responses: {
  525. 200: {
  526. description: 'success',
  527. },
  528. 404: {
  529. description: 'not found',
  530. },
  531. },
  532. security: [
  533. {
  534. token: [],
  535. },
  536. ],
  537. },
  538. post: {
  539. 'x-swagger-router-controller': 'projects',
  540. operationId: 'createZip',
  541. tags: ['Project'],
  542. description:
  543. 'Create a zip file with project content. Returns a link to be polled.',
  544. parameters: [
  545. {
  546. name: 'project_id',
  547. in: 'path',
  548. description: 'project id',
  549. required: true,
  550. type: 'string',
  551. },
  552. {
  553. name: 'version',
  554. in: 'path',
  555. description: 'numeric version',
  556. required: true,
  557. type: 'number',
  558. },
  559. ],
  560. responses: {
  561. 200: {
  562. description: 'success',
  563. schema: {
  564. $ref: '#/definitions/ZipInfo',
  565. },
  566. },
  567. 404: {
  568. description: 'not found',
  569. },
  570. },
  571. security: [
  572. {
  573. basic: [],
  574. },
  575. ],
  576. },
  577. },
  578. }