mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Improve data repo key importing https://github.com/siyuan-note/siyuan/issues/12183
This commit is contained in:
parent
efb3c5dd36
commit
6215e37418
4 changed files with 17 additions and 12 deletions
|
|
@ -272,8 +272,8 @@ ${checkUpdateHTML}
|
||||||
passwordDialog.destroy();
|
passwordDialog.destroy();
|
||||||
});
|
});
|
||||||
btnsElement[1].addEventListener("click", () => {
|
btnsElement[1].addEventListener("click", () => {
|
||||||
fetchPost("/api/repo/importRepoKey", {key: textAreaElement.value}, () => {
|
fetchPost("/api/repo/importRepoKey", {key: textAreaElement.value}, (response) => {
|
||||||
window.siyuan.config.repo.key = textAreaElement.value;
|
window.siyuan.config.repo.key = response.data.key;
|
||||||
importKeyElement.parentElement.classList.add("fn__none");
|
importKeyElement.parentElement.classList.add("fn__none");
|
||||||
importKeyElement.parentElement.nextElementSibling.classList.remove("fn__none");
|
importKeyElement.parentElement.nextElementSibling.classList.remove("fn__none");
|
||||||
passwordDialog.destroy();
|
passwordDialog.destroy();
|
||||||
|
|
|
||||||
|
|
@ -179,8 +179,8 @@ export const initAbout = () => {
|
||||||
passwordDialog.destroy();
|
passwordDialog.destroy();
|
||||||
});
|
});
|
||||||
btnsElement[1].addEventListener("click", () => {
|
btnsElement[1].addEventListener("click", () => {
|
||||||
fetchPost("/api/repo/importRepoKey", {key: textAreaElement.value}, () => {
|
fetchPost("/api/repo/importRepoKey", {key: textAreaElement.value}, (response) => {
|
||||||
window.siyuan.config.repo.key = textAreaElement.value;
|
window.siyuan.config.repo.key = response.data.key;
|
||||||
importKeyElement.parentElement.classList.add("fn__none");
|
importKeyElement.parentElement.classList.add("fn__none");
|
||||||
importKeyElement.parentElement.nextElementSibling.classList.remove("fn__none");
|
importKeyElement.parentElement.nextElementSibling.classList.remove("fn__none");
|
||||||
passwordDialog.destroy();
|
passwordDialog.destroy();
|
||||||
|
|
|
||||||
|
|
@ -350,12 +350,17 @@ func importRepoKey(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
base64Key := arg["key"].(string)
|
base64Key := arg["key"].(string)
|
||||||
if err := model.ImportRepoKey(base64Key); nil != err {
|
retKey, err := model.ImportRepoKey(base64Key)
|
||||||
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = fmt.Sprintf(model.Conf.Language(137), err)
|
ret.Msg = fmt.Sprintf(model.Conf.Language(137), err)
|
||||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret.Data = map[string]interface{}{
|
||||||
|
"key": retKey,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initRepoKeyFromPassphrase(c *gin.Context) {
|
func initRepoKeyFromPassphrase(c *gin.Context) {
|
||||||
|
|
|
||||||
|
|
@ -424,23 +424,23 @@ func statTypesByPath(files []*entity.File) (ret []*TypeCount) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportRepoKey(base64Key string) (err error) {
|
func ImportRepoKey(base64Key string) (retKey string, err error) {
|
||||||
util.PushMsg(Conf.Language(136), 3000)
|
util.PushMsg(Conf.Language(136), 3000)
|
||||||
|
|
||||||
base64Key = strings.TrimSpace(base64Key)
|
retKey = strings.TrimSpace(base64Key)
|
||||||
base64Key = gulu.Str.RemoveInvisible(base64Key)
|
retKey = gulu.Str.RemoveInvisible(retKey)
|
||||||
if 1 > len(base64Key) {
|
if 1 > len(retKey) {
|
||||||
err = errors.New(Conf.Language(142))
|
err = errors.New(Conf.Language(142))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := base64.StdEncoding.DecodeString(base64Key)
|
key, err := base64.StdEncoding.DecodeString(retKey)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("import data repo key failed: %s", err)
|
logging.LogErrorf("import data repo key failed: %s", err)
|
||||||
return errors.New(Conf.Language(157))
|
return "", errors.New(Conf.Language(157))
|
||||||
}
|
}
|
||||||
if 32 != len(key) {
|
if 32 != len(key) {
|
||||||
return errors.New(Conf.Language(157))
|
return "", errors.New(Conf.Language(157))
|
||||||
}
|
}
|
||||||
|
|
||||||
Conf.Repo.Key = key
|
Conf.Repo.Key = key
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue