projects.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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. name: 'readOnly',
  338. in: 'query',
  339. description: 'use read only database connection',
  340. required: false,
  341. type: 'boolean',
  342. },
  343. ],
  344. responses: {
  345. 200: {
  346. description: 'Success',
  347. schema: {
  348. $ref: '#/definitions/ChunkResponseRaw',
  349. },
  350. },
  351. 404: {
  352. description: 'Not Found',
  353. schema: {
  354. $ref: '#/definitions/Error',
  355. },
  356. },
  357. },
  358. },
  359. },
  360. '/projects/{project_id}/latest/persistedHistory': {
  361. get: {
  362. 'x-swagger-router-controller': 'projects',
  363. operationId: 'getLatestPersistedHistory',
  364. tags: ['Project'],
  365. description: 'Get the latest sequence of changes.',
  366. parameters: [
  367. {
  368. name: 'project_id',
  369. in: 'path',
  370. description: 'project id',
  371. required: true,
  372. type: 'string',
  373. },
  374. ],
  375. responses: {
  376. 200: {
  377. description: 'Success',
  378. schema: {
  379. $ref: '#/definitions/ChunkResponse',
  380. },
  381. },
  382. 404: {
  383. description: 'Not Found',
  384. schema: {
  385. $ref: '#/definitions/Error',
  386. },
  387. },
  388. },
  389. },
  390. },
  391. '/projects/{project_id}/versions/{version}/history': {
  392. get: {
  393. 'x-swagger-router-controller': 'projects',
  394. operationId: 'getHistory',
  395. tags: ['Project'],
  396. description:
  397. 'Get the sequence of changes that includes the given version.',
  398. parameters: [
  399. {
  400. name: 'project_id',
  401. in: 'path',
  402. description: 'project id',
  403. required: true,
  404. type: 'string',
  405. },
  406. {
  407. name: 'version',
  408. in: 'path',
  409. description: 'numeric version',
  410. required: true,
  411. type: 'number',
  412. },
  413. ],
  414. responses: {
  415. 200: {
  416. description: 'Success',
  417. schema: {
  418. $ref: '#/definitions/ChunkResponse',
  419. },
  420. },
  421. 404: {
  422. description: 'Not Found',
  423. schema: {
  424. $ref: '#/definitions/Error',
  425. },
  426. },
  427. },
  428. },
  429. },
  430. '/projects/{project_id}/versions/{version}/content': {
  431. get: {
  432. 'x-swagger-router-controller': 'projects',
  433. operationId: 'getContentAtVersion',
  434. tags: ['Project'],
  435. description: 'Get full content at the given version',
  436. parameters: [
  437. {
  438. name: 'project_id',
  439. in: 'path',
  440. description: 'project id',
  441. required: true,
  442. type: 'string',
  443. },
  444. {
  445. name: 'version',
  446. in: 'path',
  447. description: 'numeric version',
  448. required: true,
  449. type: 'number',
  450. },
  451. ],
  452. responses: {
  453. 200: {
  454. description: 'Success',
  455. schema: {
  456. $ref: '#/definitions/Snapshot',
  457. },
  458. },
  459. 404: {
  460. description: 'Not Found',
  461. schema: {
  462. $ref: '#/definitions/Error',
  463. },
  464. },
  465. },
  466. },
  467. },
  468. '/projects/{project_id}/timestamp/{timestamp}/history': {
  469. get: {
  470. 'x-swagger-router-controller': 'projects',
  471. operationId: 'getHistoryBefore',
  472. tags: ['Project'],
  473. description:
  474. 'Get the sequence of changes. ' + ' before the given timestamp',
  475. parameters: [
  476. {
  477. name: 'project_id',
  478. in: 'path',
  479. description: 'project id',
  480. required: true,
  481. type: 'string',
  482. },
  483. {
  484. name: 'timestamp',
  485. in: 'path',
  486. description: 'timestamp',
  487. required: true,
  488. type: 'string',
  489. format: 'date-time',
  490. },
  491. ],
  492. responses: {
  493. 200: {
  494. description: 'Success',
  495. schema: {
  496. $ref: '#/definitions/ChunkResponse',
  497. },
  498. },
  499. 404: {
  500. description: 'Not Found',
  501. schema: {
  502. $ref: '#/definitions/Error',
  503. },
  504. },
  505. },
  506. },
  507. },
  508. '/projects/{project_id}/version/{version}/zip': {
  509. get: {
  510. 'x-swagger-router-controller': 'projects',
  511. operationId: 'getZip',
  512. tags: ['Project'],
  513. description: 'Download zip with project content',
  514. parameters: [
  515. {
  516. name: 'project_id',
  517. in: 'path',
  518. description: 'project id',
  519. required: true,
  520. type: 'string',
  521. },
  522. {
  523. name: 'version',
  524. in: 'path',
  525. description: 'numeric version',
  526. required: true,
  527. type: 'number',
  528. },
  529. ],
  530. produces: ['application/octet-stream'],
  531. responses: {
  532. 200: {
  533. description: 'success',
  534. },
  535. 404: {
  536. description: 'not found',
  537. },
  538. },
  539. security: [
  540. {
  541. token: [],
  542. },
  543. ],
  544. },
  545. post: {
  546. 'x-swagger-router-controller': 'projects',
  547. operationId: 'createZip',
  548. tags: ['Project'],
  549. description:
  550. 'Create a zip file with project content. Returns a link to be polled.',
  551. parameters: [
  552. {
  553. name: 'project_id',
  554. in: 'path',
  555. description: 'project id',
  556. required: true,
  557. type: 'string',
  558. },
  559. {
  560. name: 'version',
  561. in: 'path',
  562. description: 'numeric version',
  563. required: true,
  564. type: 'number',
  565. },
  566. ],
  567. responses: {
  568. 200: {
  569. description: 'success',
  570. schema: {
  571. $ref: '#/definitions/ZipInfo',
  572. },
  573. },
  574. 404: {
  575. description: 'not found',
  576. },
  577. },
  578. security: [
  579. {
  580. basic: [],
  581. },
  582. ],
  583. },
  584. },
  585. }