Exemple #1
0
        protected override BasicFlatNote CreateClone()
        {
            var n = new StandardFileNote(_id, _config, _hConfig);

            using (n.SuppressDirtyChanges())
            {
                n._internalTags = _internalTags.ToList();
                n.ResyncTags();
                n._text             = _text;
                n._internaltitle    = _internaltitle;
                n._creationDate     = _creationDate;
                n._modificationDate = _modificationDate;
                n._contentVersion   = _contentVersion;
                n._authHash         = _authHash;
                n._internalRef.Synchronize(_internalRef);
                n._isPinned = _isPinned;

                return(n);
            }
        }
Exemple #2
0
        private static StandardFileNote CreateNote(ISimpleJsonRest web, StandardNoteConnection conn, APIResultItem encNote, APIResultAuthorize authToken, StandardNoteConfig cfg, StandardNoteData dat)
        {
            if (encNote.deleted)
            {
                var nd = new StandardFileNote(encNote.uuid, cfg, conn.HConfig)
                {
                    CreationDate   = encNote.created_at,
                    Text           = "",
                    InternalTitle  = "",
                    AuthHash       = encNote.auth_hash,
                    ContentVersion = StandardNoteCrypt.GetSchemaVersion(encNote.content),
                };
                nd.ModificationDate = encNote.updated_at;
                return(nd);
            }

            ContentNote content;

            try
            {
                var contentJson = StandardNoteCrypt.DecryptContent(encNote.content, encNote.enc_item_key, encNote.auth_hash, authToken.masterkey, authToken.masterauthkey);

                Logger.Debug(
                    StandardNotePlugin.Name,
                    $"DecryptContent of note {encNote.uuid:B}",
                    $"[content]:\r\n{encNote.content}\r\n" +
                    $"[enc_item_key]:\r\n{encNote.enc_item_key}\r\n" +
                    $"[auth_hash]:\r\n{encNote.auth_hash}\r\n" +
                    $"\r\n\r\n" +
                    $"[contentJson]:\r\n{contentJson}\r\n");

                content = web.ParseJsonWithoutConverter <ContentNote>(contentJson);
            }
            catch (RestException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new StandardNoteAPIException("Cannot decrypt note with local masterkey", e);
            }

            var n = new StandardFileNote(encNote.uuid, cfg, conn.HConfig);

            using (n.SuppressDirtyChanges())
            {
                n.Text           = StandardNoteConfig.REX_LINEBREAK.Replace(content.text, Environment.NewLine);
                n.InternalTitle  = content.title;
                n.AuthHash       = encNote.auth_hash;
                n.ContentVersion = StandardNoteCrypt.GetSchemaVersion(encNote.content);
                n.IsPinned       = GetAppDataBool(content.appData, APPDATA_PINNED, false);
                n.IsLocked       = GetAppDataBool(content.appData, APPDATA_LOCKED, false);

                var refTags = new List <StandardFileTagRef>();
                foreach (var cref in content.references)
                {
                    if (cref.content_type == "Note")
                    {
                        // ignore
                    }
                    else if (dat.Tags.Any(t => t.UUID == cref.uuid))
                    {
                        refTags.Add(new StandardFileTagRef(cref.uuid, dat.Tags.First(t => t.UUID == cref.uuid).Title));
                    }
                    else if (cref.content_type == "Tag")
                    {
                        Logger.Warn(StandardNotePlugin.Name, $"Reference to missing tag {cref.uuid} in note {encNote.uuid}");
                    }
                    else
                    {
                        Logger.Error(StandardNotePlugin.Name, $"Downloaded note contains an unknown reference :{cref.uuid} ({cref.content_type}) in note {encNote.uuid}");
                    }
                }

                foreach (var tref in dat.Tags.Where(tag => tag.References.Any(tref => tref == encNote.uuid)))
                {
                    refTags.Add(new StandardFileTagRef(tref.UUID, tref.Title));
                }

                refTags = refTags.DistinctBy(t => t.UUID).ToList();

                n.SetTags(refTags);
                n.SetReferences(content.references);
                n.CreationDate     = encNote.created_at;
                n.ModificationDate = encNote.updated_at;
            }

            return(n);
        }