@seafile/sdoc-editor 0.1.29 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import axios from 'axios';
4
+ var SeafileAPI = /*#__PURE__*/function () {
5
+ function SeafileAPI(server, token) {
6
+ _classCallCheck(this, SeafileAPI);
7
+ this.req = axios.create({
8
+ baseURL: server,
9
+ headers: {
10
+ Authorization: 'Token ' + token
11
+ }
12
+ });
13
+ }
14
+ _createClass(SeafileAPI, [{
15
+ key: "uploadSdocImage",
16
+ value: function uploadSdocImage(docUuid, file) {
17
+ var url = '/api/v2.1/seadoc/upload-image/' + docUuid + '/';
18
+ var form = new FormData();
19
+ form.append('file', file);
20
+ return this.req.post(url, form);
21
+ }
22
+ }, {
23
+ key: "getSdocDownloadImageUrl",
24
+ value: function getSdocDownloadImageUrl(docUuid, imageName) {
25
+ var url = '/api/v2.1/seadoc/download-image/' + docUuid + '/' + encodeURIComponent(imageName);
26
+ return this.req.get(url);
27
+ }
28
+ }]);
29
+ return SeafileAPI;
30
+ }();
31
+ export default SeafileAPI;
@@ -90,9 +90,7 @@ var ImageMenu = /*#__PURE__*/function (_React$Component) {
90
90
  var editor = _this.props.editor;
91
91
  var file = event.target.files[0];
92
92
  context.uploadLocalImage(file).then(function (fileUrl) {
93
- console.log(fileUrl);
94
93
  insertImage(editor, fileUrl, _this.selection);
95
- console.log(editor.children);
96
94
  });
97
95
  };
98
96
  _this.setInputRef = function (ref) {
@@ -5,10 +5,12 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
5
5
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
6
  import { useSelected } from '@seafile/slate-react';
7
7
  import React from 'react';
8
- import { updateImage } from './helpers';
9
8
  import classNames from 'classnames';
10
9
  import { withTranslation } from 'react-i18next';
10
+ import urlJoin from 'url-join';
11
+ import { updateImage } from './helpers';
11
12
  import ImagePreviewer from './dialogs/image-previewer';
13
+ import context from '../../../../context';
12
14
  var Image = /*#__PURE__*/function (_React$Component) {
13
15
  _inherits(Image, _React$Component);
14
16
  var _super = _createSuper(Image);
@@ -87,6 +89,13 @@ var Image = /*#__PURE__*/function (_React$Component) {
87
89
  return _this;
88
90
  }
89
91
  _createClass(Image, [{
92
+ key: "getImageURL",
93
+ value: function getImageURL(url) {
94
+ var serviceUrl = context.getSetting('serviceUrl');
95
+ var assetsUrl = context.getSetting('assetsUrl');
96
+ return urlJoin(serviceUrl, assetsUrl, url);
97
+ }
98
+ }, {
90
99
  key: "render",
91
100
  value: function render() {
92
101
  var _this$props2 = this.props,
@@ -107,7 +116,7 @@ var Image = /*#__PURE__*/function (_React$Component) {
107
116
  }, attributes), /*#__PURE__*/React.createElement("img", {
108
117
  className: imageClassName,
109
118
  ref: this.setImageRef,
110
- src: data.src,
119
+ src: this.getImageURL(data.src),
111
120
  style: imageStyle,
112
121
  draggable: false,
113
122
  alt: ""
package/dist/context.js CHANGED
@@ -1,38 +1,20 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import cookie from 'react-cookies';
4
- import { SeafileAPI } from 'seafile-js';
5
3
  import Url from 'url-parse';
6
4
  import SDocServerApi from './api/sdoc-server-api';
7
- import { getDirPath, getImageFileNameWithTimestamp } from './utils';
5
+ import SeafileAPI from './api/seafile-api';
8
6
  var Context = /*#__PURE__*/function () {
9
7
  function Context() {
10
8
  var _this = this;
11
9
  _classCallCheck(this, Context);
12
10
  this.initSettings = function () {
13
11
  _this.settings = window.seafile ? window.seafile : window.seafileConfig;
14
- var isOpenSocket = _this.getSetting('isOpenSocket');
15
- if (isOpenSocket) {
16
- _this.sdocServerApi = new SDocServerApi(_this.settings);
17
- }
18
12
  };
19
13
  this.uploadLocalImage = function (imageFile) {
20
- var repoID = _this.getSetting('repoID');
21
14
  var docUuid = _this.getSetting('docUuid');
22
- var relativePath = "images/sdoc/".concat(docUuid);
23
- return _this.api.getFileServerUploadLink(repoID, '/').then(function (res) {
24
- var uploadLink = res.data + '?ret-json=1';
25
- var name = getImageFileNameWithTimestamp();
26
- var newFile = new File([imageFile], name, {
27
- type: imageFile.type
28
- });
29
- var formData = new FormData();
30
- formData.append('parent_dir', '/');
31
- formData.append('relative_path', relativePath);
32
- formData.append('file', newFile);
33
- return _this.api.uploadImage(uploadLink, formData);
34
- }).then(function (res) {
35
- return _this._getImageURL(res.data[0].name);
15
+ return _this.api.uploadSdocImage(docUuid, imageFile).then(function (res) {
16
+ var relative_path = res.data.relative_path;
17
+ return relative_path;
36
18
  });
37
19
  };
38
20
  this.settings = null;
@@ -44,27 +26,10 @@ var Context = /*#__PURE__*/function () {
44
26
  key: "initApi",
45
27
  value: function initApi() {
46
28
  this.initSettings(); // lazy init context class
47
- var seafileAPI = new SeafileAPI();
48
- if (this.getSetting('isDevelopment')) {
49
- var server = this.getSetting('serviceUrl');
50
- var username = this.getSetting('username');
51
- var password = this.getSetting('password');
52
- seafileAPI.init({
53
- server: server,
54
- username: username,
55
- password: password
56
- });
57
- this.api = seafileAPI;
58
- return seafileAPI.login();
59
- } else {
60
- var siteRoot = this.getSetting('siteRoot');
61
- var xcsrfHeaders = cookie.load('dtable_csrftoken');
62
- seafileAPI.initForSeahubUsage({
63
- siteRoot: siteRoot,
64
- xcsrfHeaders: xcsrfHeaders
65
- });
66
- this.api = seafileAPI;
67
- }
29
+ var server = this.getSetting('serviceUrl');
30
+ var token = this.getSetting('accessToken');
31
+ this.api = new SeafileAPI(server, token);
32
+ this.sdocServerApi = new SDocServerApi(this.settings);
68
33
  }
69
34
  }, {
70
35
  key: "getSettings",
@@ -109,71 +74,13 @@ var Context = /*#__PURE__*/function () {
109
74
  }, {
110
75
  key: "getFileContent",
111
76
  value: function getFileContent() {
112
- var isOpenSocket = this.getSetting('isOpenSocket');
113
- if (isOpenSocket) {
114
- return this.getFileContent1();
115
- }
116
-
117
- // visit by shared link
118
- var rawPath = this.getSetting('rawPath');
119
- if (rawPath) {
120
- return this.api.getFileContent(rawPath);
121
- }
122
- return this.getFileContent2();
77
+ return this.sdocServerApi.getDocContent();
123
78
  }
124
79
  }, {
125
80
  key: "saveContent",
126
81
  value: function saveContent(content) {
127
- var isOpenSocket = this.getSetting('isOpenSocket');
128
- if (isOpenSocket) {
129
- return this.saveContent1(content);
130
- }
131
- return this.saveContent2(content);
132
- }
133
- }, {
134
- key: "getFileContent1",
135
- value: function getFileContent1() {
136
- return this.sdocServerApi.getDocContent();
137
- }
138
- }, {
139
- key: "saveContent1",
140
- value: function saveContent1(content) {
141
82
  return this.sdocServerApi.saveDocContent(content);
142
83
  }
143
- }, {
144
- key: "getFileContent2",
145
- value: function getFileContent2() {
146
- var _this2 = this;
147
- var repoID = this.getSetting('repoID');
148
- var docPath = this.getSetting('docPath');
149
- return this.api.getFileDownloadLink(repoID, docPath).then(function (res) {
150
- var downloadLink = res.data;
151
- return _this2.api.getFileContent(downloadLink);
152
- });
153
- }
154
- }, {
155
- key: "saveContent2",
156
- value: function saveContent2(content) {
157
- var _this3 = this;
158
- var settings = this.getSettings();
159
- var repoID = settings.repoID,
160
- docPath = settings.docPath,
161
- docName = settings.docName;
162
- var dirPath = getDirPath(docPath);
163
- return this.api.getUpdateLink(repoID, dirPath).then(function (res) {
164
- var uploadLink = res.data;
165
- return _this3.api.updateFile(uploadLink, docPath, docName, content);
166
- });
167
- }
168
- }, {
169
- key: "_getImageURL",
170
- value: function _getImageURL(fileName) {
171
- var repoID = this.getSetting('repoID');
172
- var serviceUrl = this.getSetting('serviceUrl');
173
- var docUuid = this.getSetting('docUuid');
174
- var url = serviceUrl + '/lib/' + repoID + '/file/images/sdoc/' + docUuid + '/' + fileName + '?raw=1';
175
- return url;
176
- }
177
84
  }, {
178
85
  key: "getCollaborators",
179
86
  value: function getCollaborators() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -18,6 +18,7 @@
18
18
  "reactstrap": "8.9.0",
19
19
  "slugid": "3.2.0",
20
20
  "socket.io-client": "4.6.1",
21
+ "url-join": "5.0.0",
21
22
  "url-parse": "1.5.10",
22
23
  "uuid": "9.0.0"
23
24
  },