This commit is contained in:
Daniel 2024-08-03 22:36:14 +08:00
parent efb3c5dd36
commit 6215e37418
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 17 additions and 12 deletions

View file

@ -272,8 +272,8 @@ ${checkUpdateHTML}
passwordDialog.destroy();
});
btnsElement[1].addEventListener("click", () => {
fetchPost("/api/repo/importRepoKey", {key: textAreaElement.value}, () => {
window.siyuan.config.repo.key = textAreaElement.value;
fetchPost("/api/repo/importRepoKey", {key: textAreaElement.value}, (response) => {
window.siyuan.config.repo.key = response.data.key;
importKeyElement.parentElement.classList.add("fn__none");
importKeyElement.parentElement.nextElementSibling.classList.remove("fn__none");
passwordDialog.destroy();

View file

@ -179,8 +179,8 @@ export const initAbout = () => {
passwordDialog.destroy();
});
btnsElement[1].addEventListener("click", () => {
fetchPost("/api/repo/importRepoKey", {key: textAreaElement.value}, () => {
window.siyuan.config.repo.key = textAreaElement.value;
fetchPost("/api/repo/importRepoKey", {key: textAreaElement.value}, (response) => {
window.siyuan.config.repo.key = response.data.key;
importKeyElement.parentElement.classList.add("fn__none");
importKeyElement.parentElement.nextElementSibling.classList.remove("fn__none");
passwordDialog.destroy();

View file

@ -350,12 +350,17 @@ func importRepoKey(c *gin.Context) {
}
base64Key := arg["key"].(string)
if err := model.ImportRepoKey(base64Key); nil != err {
retKey, err := model.ImportRepoKey(base64Key)
if nil != err {
ret.Code = -1
ret.Msg = fmt.Sprintf(model.Conf.Language(137), err)
ret.Data = map[string]interface{}{"closeTimeout": 5000}
return
}
ret.Data = map[string]interface{}{
"key": retKey,
}
}
func initRepoKeyFromPassphrase(c *gin.Context) {

View file

@ -424,23 +424,23 @@ func statTypesByPath(files []*entity.File) (ret []*TypeCount) {
return
}
func ImportRepoKey(base64Key string) (err error) {
func ImportRepoKey(base64Key string) (retKey string, err error) {
util.PushMsg(Conf.Language(136), 3000)
base64Key = strings.TrimSpace(base64Key)
base64Key = gulu.Str.RemoveInvisible(base64Key)
if 1 > len(base64Key) {
retKey = strings.TrimSpace(base64Key)
retKey = gulu.Str.RemoveInvisible(retKey)
if 1 > len(retKey) {
err = errors.New(Conf.Language(142))
return
}
key, err := base64.StdEncoding.DecodeString(base64Key)
key, err := base64.StdEncoding.DecodeString(retKey)
if nil != 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) {
return errors.New(Conf.Language(157))
return "", errors.New(Conf.Language(157))
}
Conf.Repo.Key = key