projects.js 15 KB

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