versionmodel.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Copyright (c) 2015
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. * @author Robin Appelman <robin@icewind.nl>
  6. * @author Vincent Petry <vincent@nextcloud.com>
  7. *
  8. * @license AGPL-3.0-or-later
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. (function() {
  25. /**
  26. * @memberof OCA.Versions
  27. */
  28. const VersionModel = OC.Backbone.Model.extend({
  29. sync: OC.Backbone.davSync,
  30. davProperties: {
  31. size: '{DAV:}getcontentlength',
  32. mimetype: '{DAV:}getcontenttype',
  33. timestamp: '{DAV:}getlastmodified',
  34. },
  35. /**
  36. * Restores the original file to this revision
  37. *
  38. * @param {object} [options] options
  39. * @return {Promise}
  40. */
  41. revert(options) {
  42. options = options ? _.clone(options) : {}
  43. const model = this
  44. const client = this.get('client')
  45. return client.move('/versions/' + this.get('fileId') + '/' + this.get('id'), '/restore/target', true)
  46. .done(function() {
  47. if (options.success) {
  48. options.success.call(options.context, model, {}, options)
  49. }
  50. model.trigger('revert', model, options)
  51. })
  52. .fail(function() {
  53. if (options.error) {
  54. options.error.call(options.context, model, {}, options)
  55. }
  56. model.trigger('error', model, {}, options)
  57. })
  58. },
  59. getFullPath() {
  60. return this.get('fullPath')
  61. },
  62. getPreviewUrl() {
  63. const url = OC.generateUrl('/apps/files_versions/preview')
  64. const params = {
  65. file: this.get('fullPath'),
  66. version: this.get('id'),
  67. }
  68. return url + '?' + OC.buildQueryString(params)
  69. },
  70. getDownloadUrl() {
  71. return OC.linkToRemoteBase('dav') + '/versions/' + this.get('user') + '/versions/' + this.get('fileId') + '/' + this.get('id')
  72. },
  73. })
  74. OCA.Versions = OCA.Versions || {}
  75. OCA.Versions.VersionModel = VersionModel
  76. })()