Add files via upload
This commit is contained in:
174
src/api/note.js
174
src/api/note.js
@@ -1,109 +1,99 @@
|
||||
import axios from "axios";
|
||||
import Jquery from "jquery";
|
||||
import {getStoreKey} from "@/api/lock";
|
||||
import { getStoreKey } from "@/api/lock";
|
||||
import storage from "@/libs/storage";
|
||||
import { md5 } from "@/libs/secret";
|
||||
|
||||
const servicePath = 'https://service.flagnote.com';
|
||||
const servicePath = "https://flagnote.com";
|
||||
//const servicePath = "http://localhost:8080";
|
||||
|
||||
export function saveNote(noteForm) {
|
||||
let storeKey = getStoreKey(noteForm.key);
|
||||
let storeText = storage.local.getText(storeKey + '.text');
|
||||
let note = {
|
||||
"lock": storeText.substring(0, 1),
|
||||
"cipher": storeText.substring(2, 34),
|
||||
"text": storeText.substring(35+16),
|
||||
"key": noteForm.key
|
||||
}
|
||||
export function saveNote(noteForm, secret) {
|
||||
let storeKey = secret.storeKey;
|
||||
|
||||
return axios({
|
||||
url: servicePath+'/note/' + noteForm.key,
|
||||
method: 'post',
|
||||
data: note
|
||||
}
|
||||
)
|
||||
let storeInfo = storage.local.getText(storeKey);
|
||||
let starray = storeInfo.split("|");
|
||||
|
||||
let note = {
|
||||
lock: starray[0],
|
||||
cipher: starray[1],
|
||||
text: starray[4],
|
||||
key: noteForm.key,
|
||||
};
|
||||
|
||||
let bufferArrary = eval("[" + note.text + "]");
|
||||
let array = Uint8Array.from(bufferArrary);
|
||||
let blob = new Blob([array], { type: "application/octet-stream" });
|
||||
let form = new FormData();
|
||||
form.append("file", blob, noteForm.key);
|
||||
form.append("cipher", note.cipher);
|
||||
form.append("lock", note.lock);
|
||||
form.append("key", note.key);
|
||||
form.append("md5", md5(note.text));
|
||||
|
||||
let config = {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
};
|
||||
|
||||
return axios({
|
||||
url: servicePath + "/note/" + noteForm.key,
|
||||
method: "post",
|
||||
data: form,
|
||||
config: config,
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteNote(key) {
|
||||
let storeKey = getStoreKey(key);
|
||||
let storeText = storage.local.getText(storeKey + '.text');
|
||||
let note = {
|
||||
"cipher": storeText.substring(2, 34),
|
||||
"key": key
|
||||
}
|
||||
let storeKey = getStoreKey(key);
|
||||
let storeInfo = storage.local.getText(storeKey);
|
||||
let note = {
|
||||
cipher: storeInfo.substring(2, 34),
|
||||
key: key,
|
||||
};
|
||||
|
||||
return axios({
|
||||
url: servicePath+'/note/' + key +'/delete',
|
||||
method: 'post',
|
||||
data: note
|
||||
}
|
||||
)
|
||||
return axios({
|
||||
url: servicePath + "/note/" + key + "/delete",
|
||||
method: "post",
|
||||
data: note,
|
||||
});
|
||||
}
|
||||
|
||||
// export function getSecretKey(key, password) {
|
||||
// console.log("getSecretKey");
|
||||
// let secretKey = '';
|
||||
// Jquery.ajax({
|
||||
// method: 'POST',
|
||||
// url: '/note/' + key + "/secretKey",
|
||||
// async: false,
|
||||
// contentType: 'application/json',
|
||||
// dataTeyp: 'json',
|
||||
// data: JSON.stringify({'password': password}),
|
||||
// success: function (data) {
|
||||
// secretKey = data;
|
||||
// },
|
||||
// error: function () {
|
||||
// alert('服务器链接异常 ');
|
||||
// },
|
||||
// });
|
||||
// return secretKey;
|
||||
// }
|
||||
|
||||
export function getNoteBlob(key) {
|
||||
return axios({
|
||||
url: servicePath + "/note/" + key,
|
||||
method: "get",
|
||||
responseType: "blob",
|
||||
ignoreError: 1,
|
||||
original: true,
|
||||
source: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function getNoteMeta(key) {
|
||||
let noteMeta = {};
|
||||
Jquery.ajax({
|
||||
method: 'GET',
|
||||
url: servicePath+'/note/' + key + "/noteMeta",
|
||||
async: false,
|
||||
success: function (data) {
|
||||
noteMeta = eval(data); //eval("(" + data + ")");
|
||||
},
|
||||
error: function () {
|
||||
noteMeta = null;
|
||||
},
|
||||
});
|
||||
return noteMeta;
|
||||
let url = servicePath + "/note/" + key + "/noteMeta";
|
||||
let noteMeta = ajaxGet(url);
|
||||
return noteMeta;
|
||||
}
|
||||
|
||||
export function getNote(key) {
|
||||
let noteObject = {};
|
||||
Jquery.ajax({
|
||||
method: 'GET',
|
||||
url: servicePath + '/note/' + key,
|
||||
async: false,
|
||||
success: function (data) {
|
||||
noteObject = eval(data);
|
||||
},
|
||||
error: function () {
|
||||
noteObject = null;
|
||||
},
|
||||
});
|
||||
return noteObject;
|
||||
}
|
||||
|
||||
export function getKeyMeta() {
|
||||
let keyMeta = {};
|
||||
Jquery.ajax({
|
||||
method: 'GET',
|
||||
url: servicePath+'/note/keyMeta',
|
||||
async: false,
|
||||
success: function (data) {
|
||||
keyMeta = eval(data); //eval("(" + data + ")");
|
||||
},
|
||||
error: function () {
|
||||
keyMeta = null;
|
||||
},
|
||||
});
|
||||
return keyMeta;
|
||||
let url = servicePath + "/note/keyMeta";
|
||||
let keyMeta = ajaxGet(url);
|
||||
return keyMeta;
|
||||
}
|
||||
|
||||
export function ajaxGet(url) {
|
||||
let data = {};
|
||||
let xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.open("GET", url, false);
|
||||
xmlhttp.onreadystatechange = () => {
|
||||
if (xmlhttp.readyState == 4) {
|
||||
if (xmlhttp.status == 200 || xmlhttp.status == 304) {
|
||||
if(xmlhttp.responseText){
|
||||
data = JSON.parse(xmlhttp.responseText);
|
||||
}else{
|
||||
data ={};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
xmlhttp.send();
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user