This commit is contained in:
zadam 2019-11-01 23:05:33 +01:00
parent 2af86927b0
commit 475fddeec1
8 changed files with 84 additions and 49 deletions

View File

@ -430,199 +430,233 @@ parentNoteId</ColNames>
<NotNull>1</NotNull> <NotNull>1</NotNull>
<DefaultExpression>0</DefaultExpression> <DefaultExpression>0</DefaultExpression>
</column> </column>
<column id="97" parent="12" name="dateCreated"> <column id="97" parent="12" name="isErased">
<Position>8</Position> <Position>8</Position>
<DataType>TEXT|0s</DataType> <DataType>INT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
<DefaultExpression>0</DefaultExpression>
</column> </column>
<column id="98" parent="12" name="dateModified"> <column id="98" parent="12" name="dateCreated">
<Position>9</Position> <Position>9</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="99" parent="12" name="utcDateCreated"> <column id="99" parent="12" name="dateModified">
<Position>10</Position> <Position>10</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="100" parent="12" name="utcDateModified"> <column id="100" parent="12" name="utcDateCreated">
<Position>11</Position> <Position>11</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<index id="101" parent="12" name="sqlite_autoindex_notes_1"> <column id="101" parent="12" name="utcDateModified">
<Position>12</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<index id="102" parent="12" name="sqlite_autoindex_notes_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<ColumnCollations></ColumnCollations> <ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<key id="102" parent="12"> <index id="103" parent="12" name="IDX_notes_title">
<ColNames>title</ColNames>
<ColumnCollations></ColumnCollations>
</index>
<index id="104" parent="12" name="IDX_notes_type">
<ColNames>type</ColNames>
<ColumnCollations></ColumnCollations>
</index>
<index id="105" parent="12" name="IDX_notes_isDeleted">
<ColNames>isDeleted</ColNames>
<ColumnCollations></ColumnCollations>
</index>
<index id="106" parent="12" name="IDX_notes_dateCreated">
<ColNames>dateCreated</ColNames>
<ColumnCollations></ColumnCollations>
</index>
<index id="107" parent="12" name="IDX_notes_dateModified">
<ColNames>dateModified</ColNames>
<ColumnCollations></ColumnCollations>
</index>
<index id="108" parent="12" name="IDX_notes_utcDateCreated">
<ColNames>utcDateCreated</ColNames>
<ColumnCollations></ColumnCollations>
</index>
<index id="109" parent="12" name="IDX_notes_utcDateModified">
<ColNames>utcDateModified</ColNames>
<ColumnCollations></ColumnCollations>
</index>
<key id="110" parent="12">
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<Primary>1</Primary> <Primary>1</Primary>
<UnderlyingIndexName>sqlite_autoindex_notes_1</UnderlyingIndexName> <UnderlyingIndexName>sqlite_autoindex_notes_1</UnderlyingIndexName>
</key> </key>
<column id="103" parent="13" name="name"> <column id="111" parent="13" name="name">
<Position>1</Position> <Position>1</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="104" parent="13" name="value"> <column id="112" parent="13" name="value">
<Position>2</Position> <Position>2</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
</column> </column>
<column id="105" parent="13" name="isSynced"> <column id="113" parent="13" name="isSynced">
<Position>3</Position> <Position>3</Position>
<DataType>INTEGER|0s</DataType> <DataType>INTEGER|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
<DefaultExpression>0</DefaultExpression> <DefaultExpression>0</DefaultExpression>
</column> </column>
<column id="106" parent="13" name="hash"> <column id="114" parent="13" name="hash">
<Position>4</Position> <Position>4</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
<DefaultExpression>&quot;&quot;</DefaultExpression> <DefaultExpression>&quot;&quot;</DefaultExpression>
</column> </column>
<column id="107" parent="13" name="utcDateCreated"> <column id="115" parent="13" name="utcDateCreated">
<Position>5</Position> <Position>5</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="108" parent="13" name="utcDateModified"> <column id="116" parent="13" name="utcDateModified">
<Position>6</Position> <Position>6</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<index id="109" parent="13" name="sqlite_autoindex_options_1"> <index id="117" parent="13" name="sqlite_autoindex_options_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>name</ColNames> <ColNames>name</ColNames>
<ColumnCollations></ColumnCollations> <ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<key id="110" parent="13"> <key id="118" parent="13">
<ColNames>name</ColNames> <ColNames>name</ColNames>
<Primary>1</Primary> <Primary>1</Primary>
<UnderlyingIndexName>sqlite_autoindex_options_1</UnderlyingIndexName> <UnderlyingIndexName>sqlite_autoindex_options_1</UnderlyingIndexName>
</key> </key>
<column id="111" parent="14" name="noteId"> <column id="119" parent="14" name="noteId">
<Position>1</Position> <Position>1</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="112" parent="14" name="notePath"> <column id="120" parent="14" name="notePath">
<Position>2</Position> <Position>2</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="113" parent="14" name="hash"> <column id="121" parent="14" name="hash">
<Position>3</Position> <Position>3</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
<DefaultExpression>&quot;&quot;</DefaultExpression> <DefaultExpression>&quot;&quot;</DefaultExpression>
</column> </column>
<column id="114" parent="14" name="utcDateCreated"> <column id="122" parent="14" name="utcDateCreated">
<Position>4</Position> <Position>4</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="115" parent="14" name="isDeleted"> <column id="123" parent="14" name="isDeleted">
<Position>5</Position> <Position>5</Position>
<DataType>INT|0s</DataType> <DataType>INT|0s</DataType>
</column> </column>
<index id="116" parent="14" name="sqlite_autoindex_recent_notes_1"> <index id="124" parent="14" name="sqlite_autoindex_recent_notes_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<ColumnCollations></ColumnCollations> <ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<key id="117" parent="14"> <key id="125" parent="14">
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<Primary>1</Primary> <Primary>1</Primary>
<UnderlyingIndexName>sqlite_autoindex_recent_notes_1</UnderlyingIndexName> <UnderlyingIndexName>sqlite_autoindex_recent_notes_1</UnderlyingIndexName>
</key> </key>
<column id="118" parent="15" name="sourceId"> <column id="126" parent="15" name="sourceId">
<Position>1</Position> <Position>1</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="119" parent="15" name="utcDateCreated"> <column id="127" parent="15" name="utcDateCreated">
<Position>2</Position> <Position>2</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<index id="120" parent="15" name="sqlite_autoindex_source_ids_1"> <index id="128" parent="15" name="sqlite_autoindex_source_ids_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>sourceId</ColNames> <ColNames>sourceId</ColNames>
<ColumnCollations></ColumnCollations> <ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<key id="121" parent="15"> <key id="129" parent="15">
<ColNames>sourceId</ColNames> <ColNames>sourceId</ColNames>
<Primary>1</Primary> <Primary>1</Primary>
<UnderlyingIndexName>sqlite_autoindex_source_ids_1</UnderlyingIndexName> <UnderlyingIndexName>sqlite_autoindex_source_ids_1</UnderlyingIndexName>
</key> </key>
<column id="122" parent="16" name="type"> <column id="130" parent="16" name="type">
<Position>1</Position> <Position>1</Position>
<DataType>text|0s</DataType> <DataType>text|0s</DataType>
</column> </column>
<column id="123" parent="16" name="name"> <column id="131" parent="16" name="name">
<Position>2</Position> <Position>2</Position>
<DataType>text|0s</DataType> <DataType>text|0s</DataType>
</column> </column>
<column id="124" parent="16" name="tbl_name"> <column id="132" parent="16" name="tbl_name">
<Position>3</Position> <Position>3</Position>
<DataType>text|0s</DataType> <DataType>text|0s</DataType>
</column> </column>
<column id="125" parent="16" name="rootpage"> <column id="133" parent="16" name="rootpage">
<Position>4</Position> <Position>4</Position>
<DataType>int|0s</DataType> <DataType>int|0s</DataType>
</column> </column>
<column id="126" parent="16" name="sql"> <column id="134" parent="16" name="sql">
<Position>5</Position> <Position>5</Position>
<DataType>text|0s</DataType> <DataType>text|0s</DataType>
</column> </column>
<column id="127" parent="17" name="name"> <column id="135" parent="17" name="name">
<Position>1</Position> <Position>1</Position>
</column> </column>
<column id="128" parent="17" name="seq"> <column id="136" parent="17" name="seq">
<Position>2</Position> <Position>2</Position>
</column> </column>
<column id="129" parent="18" name="id"> <column id="137" parent="18" name="id">
<Position>1</Position> <Position>1</Position>
<DataType>INTEGER|0s</DataType> <DataType>INTEGER|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
<SequenceIdentity>1</SequenceIdentity> <SequenceIdentity>1</SequenceIdentity>
</column> </column>
<column id="130" parent="18" name="entityName"> <column id="138" parent="18" name="entityName">
<Position>2</Position> <Position>2</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="131" parent="18" name="entityId"> <column id="139" parent="18" name="entityId">
<Position>3</Position> <Position>3</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="132" parent="18" name="sourceId"> <column id="140" parent="18" name="sourceId">
<Position>4</Position> <Position>4</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="133" parent="18" name="utcSyncDate"> <column id="141" parent="18" name="utcSyncDate">
<Position>5</Position> <Position>5</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<index id="134" parent="18" name="IDX_sync_entityName_entityId"> <index id="142" parent="18" name="IDX_sync_entityName_entityId">
<ColNames>entityName <ColNames>entityName
entityId</ColNames> entityId</ColNames>
<ColumnCollations></ColumnCollations> <ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<index id="135" parent="18" name="IDX_sync_utcSyncDate"> <index id="143" parent="18" name="IDX_sync_utcSyncDate">
<ColNames>utcSyncDate</ColNames> <ColNames>utcSyncDate</ColNames>
<ColumnCollations></ColumnCollations> <ColumnCollations></ColumnCollations>
</index> </index>
<key id="136" parent="18"> <key id="144" parent="18">
<ColNames>id</ColNames> <ColNames>id</ColNames>
<Primary>1</Primary> <Primary>1</Primary>
</key> </key>

View File

@ -52,7 +52,7 @@ class Note extends Entity {
this.isContentAvailable = protectedSessionService.isProtectedSessionAvailable(); this.isContentAvailable = protectedSessionService.isProtectedSessionAvailable();
if (this.isContentAvailable) { if (this.isContentAvailable) {
this.title = protectedSessionService.decrypt(this.title); this.title = protectedSessionService.decrypt(this.title).toString();
} }
else { else {
this.title = "[protected]"; this.title = "[protected]";

View File

@ -37,7 +37,7 @@ class NoteRevision extends Entity {
if (this.isProtected) { if (this.isProtected) {
if (protectedSessionService.isProtectedSessionAvailable()) { if (protectedSessionService.isProtectedSessionAvailable()) {
this.title = protectedSessionService.decrypt(this.title); this.title = protectedSessionService.decrypt(this.title).toString();
} }
else { else {
this.title = "[Protected]"; this.title = "[Protected]";

View File

@ -41,8 +41,8 @@ async function getRecentChanges() {
for (const change of recentChanges) { for (const change of recentChanges) {
if (change.current_isProtected) { if (change.current_isProtected) {
if (protectedSessionService.isProtectedSessionAvailable()) { if (protectedSessionService.isProtectedSessionAvailable()) {
change.title = protectedSessionService.decrypt(change.title); change.title = protectedSessionService.decrypt(change.title).toString();
change.current_title = protectedSessionService.decrypt(change.current_title); change.current_title = protectedSessionService.decrypt(change.current_title).toString();
} }
else { else {
change.title = change.current_title = "[Protected]"; change.title = change.current_title = "[Protected]";

View File

@ -34,6 +34,7 @@ async function getHashes() {
note_contents: await getHash("note_contents", "noteId"), note_contents: await getHash("note_contents", "noteId"),
branches: await getHash(Branch.entityName, Branch.primaryKeyName), branches: await getHash(Branch.entityName, Branch.primaryKeyName),
note_revisions: await getHash(NoteRevision.entityName, NoteRevision.primaryKeyName), note_revisions: await getHash(NoteRevision.entityName, NoteRevision.primaryKeyName),
note_revision_contents: await getHash("note_revision_contents", "noteRevisionId"),
recent_notes: await getHash(RecentNote.entityName, RecentNote.primaryKeyName), recent_notes: await getHash(RecentNote.entityName, RecentNote.primaryKeyName),
options: await getHash(Option.entityName, Option.primaryKeyName, "isSynced = 1"), options: await getHash(Option.entityName, Option.primaryKeyName, "isSynced = 1"),
attributes: await getHash(Attribute.entityName, Attribute.primaryKeyName), attributes: await getHash(Attribute.entityName, Attribute.primaryKeyName),

View File

@ -54,7 +54,7 @@ async function loadProtectedNotes() {
protectedNoteTitles = await sql.getMap(`SELECT noteId, title FROM notes WHERE isDeleted = 0 AND isProtected = 1`); protectedNoteTitles = await sql.getMap(`SELECT noteId, title FROM notes WHERE isDeleted = 0 AND isProtected = 1`);
for (const noteId in protectedNoteTitles) { for (const noteId in protectedNoteTitles) {
protectedNoteTitles[noteId] = protectedSessionService.decrypt(protectedNoteTitles[noteId]); protectedNoteTitles[noteId] = protectedSessionService.decrypt(protectedNoteTitles[noteId]).toString();
} }
} }

View File

@ -4,7 +4,7 @@ async function getOption(name) {
const option = await require('./repository').getOption(name); const option = await require('./repository').getOption(name);
if (!option) { if (!option) {
throw new Error("Option " + name + " doesn't exist"); throw new Error(`Option ${name} doesn't exist`);
} }
return option.value; return option.value;

View File

@ -37,7 +37,7 @@ function isProtectedSessionAvailable() {
function decryptNotes(notes) { function decryptNotes(notes) {
for (const note of notes) { for (const note of notes) {
if (note.isProtected) { if (note.isProtected) {
note.title = decrypt(note.title); note.title = decrypt(note.title).toString();
} }
} }
} }
@ -47,7 +47,7 @@ function encrypt(plainText) {
} }
function decrypt(cipherText) { function decrypt(cipherText) {
return dataEncryptionService.encrypt(getDataKey(), cipherText); return dataEncryptionService.decrypt(getDataKey(), cipherText);
} }
module.exports = { module.exports = {