mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-26 07:22:34 +00:00
update image dialog, add download, delete and view original image button (#6670)
* update image dialog, add download, delete and view original image button * update react-image-lightbox * add-image-rotate-api * support restore in image previewer * support image rotate * upgrade react-image-lightbox * fix bug - first image auto previewed in list layout, improve delete and restore action * remove raise * fix last line --------- Co-authored-by: r350178982 <32759763+r350178982@users.noreply.github.com> Co-authored-by: Michael An <2331806369@qq.com>
This commit is contained in:
61
frontend/src/utils/image-api.js
Normal file
61
frontend/src/utils/image-api.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import cookie from 'react-cookies';
|
||||
import axios from 'axios';
|
||||
import { siteRoot } from './constants';
|
||||
|
||||
class ImageAPI {
|
||||
|
||||
init({ server, username, password, token }) {
|
||||
this.server = server;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.token = token;
|
||||
if (this.token && this.server) {
|
||||
this.req = axios.create({
|
||||
baseURL: this.server,
|
||||
headers: { 'Authorization': 'Token ' + this.token },
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
initForSeahubUsage({ siteRoot, xcsrfHeaders }) {
|
||||
if (siteRoot && siteRoot.charAt(siteRoot.length - 1) === '/') {
|
||||
var server = siteRoot.substring(0, siteRoot.length - 1);
|
||||
this.server = server;
|
||||
} else {
|
||||
this.server = siteRoot;
|
||||
}
|
||||
|
||||
this.req = axios.create({
|
||||
headers: {
|
||||
'X-CSRFToken': xcsrfHeaders,
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
_sendPostRequest(url, form) {
|
||||
if (form.getHeaders) {
|
||||
return this.req.post(url, form, {
|
||||
headers: form.getHeaders()
|
||||
});
|
||||
} else {
|
||||
return this.req.post(url, form);
|
||||
}
|
||||
}
|
||||
|
||||
rotateImage(repoID, path, angle) {
|
||||
let url = `${this.server}/api/v2.1/repos/${repoID}/image-rotate/`;
|
||||
let form = new FormData();
|
||||
form.append('path', path);
|
||||
form.append('angle', angle);
|
||||
return this._sendPostRequest(url, form);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let imageAPI = new ImageAPI();
|
||||
let xcsrfHeaders = cookie.load('sfcsrftoken');
|
||||
imageAPI.initForSeahubUsage({ siteRoot, xcsrfHeaders });
|
||||
|
||||
export default imageAPI;
|
Reference in New Issue
Block a user