Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

Commit

Permalink
Remove bookmark folderId; add parentFolderObjectId
Browse files Browse the repository at this point in the history
Auditors: @diracdeltas

Fix #47
  • Loading branch information
ayumi committed Jan 24, 2017
1 parent dd90af6 commit 2953593
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 65 deletions.
3 changes: 3 additions & 0 deletions client/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ const startSync = (requester) => {
// Workaround #17
record.deviceId = new Uint8Array(record.deviceId)
record.objectId = new Uint8Array(record.objectId)
if (record.bookmark && record.bookmark.parentFolderObjectId) {
record.bookmark.parentFolderObjectId = new Uint8Array(record.bookmark.parentFolderObjectId)
}
logSync(`sending record: ${JSON.stringify(record)}`)
requester.put(proto.categories[category], requester.encrypt(record))
})
Expand Down
4 changes: 2 additions & 2 deletions lib/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ message SyncRecord {
message Bookmark {
Site site = 1;
bool isFolder = 2;
uint32 folderId = 3;
uint32 parentFolderId = 4;
bytes parentFolderObjectId = 3;
int32 index = 4;

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas Jan 24, 2017

Member

any reason not to use uint32?

This comment has been minimized.

Copy link
@ayumi

ayumi Jan 24, 2017

Author Contributor

i forgot 🦁

This comment has been minimized.

Copy link
@ayumi

ayumi Jan 24, 2017

Author Contributor

i'll fix it

}
message SiteSetting {
string hostPattern = 1;
Expand Down
75 changes: 48 additions & 27 deletions lib/api.proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@
* @returns {api.Credentials} Credentials
*/
Credentials.fromObject = function fromObject(object) {
if (object instanceof $root.api.Credentials)
return object;
var message = new $root.api.Credentials();
if (object.aws !== undefined && object.aws !== null)
message.aws = $types[0].fromObject(object.aws);
Expand Down Expand Up @@ -404,6 +406,8 @@
* @returns {api.Credentials.Aws} Aws
*/
Aws.fromObject = function fromObject(object) {
if (object instanceof $root.api.Credentials.Aws)
return object;
var message = new $root.api.Credentials.Aws();
if (object.accessKeyId !== undefined && object.accessKeyId !== null)
message.accessKeyId = String(object.accessKeyId);
Expand Down Expand Up @@ -621,6 +625,8 @@
* @returns {api.Credentials.S3Post} S3Post
*/
S3Post.fromObject = function fromObject(object) {
if (object instanceof $root.api.Credentials.S3Post)
return object;
var message = new $root.api.Credentials.S3Post();
if (object.AWSAccessKeyId !== undefined && object.AWSAccessKeyId !== null)
message.AWSAccessKeyId = String(object.AWSAccessKeyId);
Expand Down Expand Up @@ -827,6 +833,8 @@
* @returns {api.SecretboxRecord} SecretboxRecord
*/
SecretboxRecord.fromObject = function fromObject(object) {
if (object instanceof $root.api.SecretboxRecord)
return object;
var message = new $root.api.SecretboxRecord();
if (object.encryptedData !== undefined && object.encryptedData !== null)
if (typeof object.encryptedData === "string")
Expand Down Expand Up @@ -1129,6 +1137,8 @@
* @returns {api.SyncRecord} SyncRecord
*/
SyncRecord.fromObject = function fromObject(object) {
if (object instanceof $root.api.SyncRecord)
return object;
var message = new $root.api.SyncRecord();
switch (object.action) {
case "CREATE":
Expand Down Expand Up @@ -1408,6 +1418,8 @@
* @returns {api.SyncRecord.Site} Site
*/
Site.fromObject = function fromObject(object) {
if (object instanceof $root.api.SyncRecord.Site)
return object;
var message = new $root.api.SyncRecord.Site();
if (object.location !== undefined && object.location !== null)
message.location = String(object.location);
Expand Down Expand Up @@ -1537,16 +1549,16 @@
Bookmark.prototype.isFolder = false;

/**
* Bookmark folderId.
* @type {number}
* Bookmark parentFolderObjectId.
* @type {Uint8Array}
*/
Bookmark.prototype.folderId = 0;
Bookmark.prototype.parentFolderObjectId = $util.newBuffer([]);

/**
* Bookmark parentFolderId.
* Bookmark index.
* @type {number}
*/
Bookmark.prototype.parentFolderId = 0;
Bookmark.prototype.index = 0;

// Lazily resolved type references
var $types = {
Expand Down Expand Up @@ -1575,10 +1587,10 @@
$types[0].encode(message.site, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim();
if (message.isFolder !== undefined && message.hasOwnProperty("isFolder"))
writer.uint32(/* id 2, wireType 0 =*/16).bool(message.isFolder);
if (message.folderId !== undefined && message.hasOwnProperty("folderId"))
writer.uint32(/* id 3, wireType 0 =*/24).uint32(message.folderId);
if (message.parentFolderId !== undefined && message.hasOwnProperty("parentFolderId"))
writer.uint32(/* id 4, wireType 0 =*/32).uint32(message.parentFolderId);
if (message.parentFolderObjectId && message.hasOwnProperty("parentFolderObjectId"))
writer.uint32(/* id 3, wireType 2 =*/26).bytes(message.parentFolderObjectId);
if (message.index !== undefined && message.hasOwnProperty("index"))
writer.uint32(/* id 4, wireType 0 =*/32).int32(message.index);
return writer;
};

Expand Down Expand Up @@ -1612,10 +1624,10 @@
message.isFolder = reader.bool();
break;
case 3:
message.folderId = reader.uint32();
message.parentFolderObjectId = reader.bytes();
break;
case 4:
message.parentFolderId = reader.uint32();
message.index = reader.int32();
break;
default:
reader.skipType(tag & 7);
Expand Down Expand Up @@ -1650,12 +1662,12 @@
if (message.isFolder !== undefined)
if (typeof message.isFolder !== "boolean")
return "isFolder: boolean expected";
if (message.folderId !== undefined)
if (!$util.isInteger(message.folderId))
return "folderId: integer expected";
if (message.parentFolderId !== undefined)
if (!$util.isInteger(message.parentFolderId))
return "parentFolderId: integer expected";
if (message.parentFolderObjectId !== undefined)
if (!(message.parentFolderObjectId && typeof message.parentFolderObjectId.length === "number" || $util.isString(message.parentFolderObjectId)))
return "parentFolderObjectId: buffer expected";
if (message.index !== undefined)
if (!$util.isInteger(message.index))
return "index: integer expected";
return null;
};

Expand All @@ -1665,15 +1677,20 @@
* @returns {api.SyncRecord.Bookmark} Bookmark
*/
Bookmark.fromObject = function fromObject(object) {
if (object instanceof $root.api.SyncRecord.Bookmark)
return object;
var message = new $root.api.SyncRecord.Bookmark();
if (object.site !== undefined && object.site !== null)
message.site = $types[0].fromObject(object.site);
if (object.isFolder !== undefined && object.isFolder !== null)
message.isFolder = Boolean(object.isFolder);
if (object.folderId !== undefined && object.folderId !== null)
message.folderId = object.folderId >>> 0;
if (object.parentFolderId !== undefined && object.parentFolderId !== null)
message.parentFolderId = object.parentFolderId >>> 0;
if (object.parentFolderObjectId !== undefined && object.parentFolderObjectId !== null)
if (typeof object.parentFolderObjectId === "string")
$util.base64.decode(object.parentFolderObjectId, message.parentFolderObjectId = $util.newBuffer($util.base64.length(object.parentFolderObjectId)), 0);
else if (object.parentFolderObjectId && object.parentFolderObjectId.length)
message.parentFolderObjectId = object.parentFolderObjectId;
if (object.index !== undefined && object.index !== null)
message.index = object.index | 0;
return message;
};

Expand All @@ -1698,17 +1715,17 @@
if (options.defaults) {
object.site = null;
object.isFolder = false;
object.folderId = 0;
object.parentFolderId = 0;
object.parentFolderObjectId = options.bytes === String ? "" : [];
object.index = 0;
}
if (message.site !== undefined && message.site !== null && message.hasOwnProperty("site"))
object.site = $types[0].toObject(message.site, options);
if (message.isFolder !== undefined && message.isFolder !== null && message.hasOwnProperty("isFolder"))
object.isFolder = message.isFolder;
if (message.folderId !== undefined && message.folderId !== null && message.hasOwnProperty("folderId"))
object.folderId = message.folderId;
if (message.parentFolderId !== undefined && message.parentFolderId !== null && message.hasOwnProperty("parentFolderId"))
object.parentFolderId = message.parentFolderId;
if (message.parentFolderObjectId !== undefined && message.parentFolderObjectId !== null && message.hasOwnProperty("parentFolderObjectId"))
object.parentFolderObjectId = options.bytes === String ? $util.base64.encode(message.parentFolderObjectId, 0, message.parentFolderObjectId.length) : options.bytes === Array ? Array.prototype.slice.call(message.parentFolderObjectId) : message.parentFolderObjectId;
if (message.index !== undefined && message.index !== null && message.hasOwnProperty("index"))
object.index = message.index;
return object;
};

Expand Down Expand Up @@ -2018,6 +2035,8 @@
* @returns {api.SyncRecord.SiteSetting} SiteSetting
*/
SiteSetting.fromObject = function fromObject(object) {
if (object instanceof $root.api.SyncRecord.SiteSetting)
return object;
var message = new $root.api.SyncRecord.SiteSetting();
if (object.hostPattern !== undefined && object.hostPattern !== null)
message.hostPattern = String(object.hostPattern);
Expand Down Expand Up @@ -2294,6 +2313,8 @@
* @returns {api.SyncRecord.Device} Device
*/
Device.fromObject = function fromObject(object) {
if (object instanceof $root.api.SyncRecord.Device)
return object;
var message = new $root.api.SyncRecord.Device();
if (object.name !== undefined && object.name !== null)
message.name = String(object.name);
Expand Down
4 changes: 2 additions & 2 deletions test/client/recordUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ test('recordUtil.syncRecordAsJS()', (t) => {

const bookmark = serializer.api.SyncRecord.Bookmark.create({
site,
index: 1,
isFolder: false,
folderId: 0,
parentFolderId: 0
parentFolderObjectId: testHelper.newUuid()
})
conversionEquals({ objectData: 'bookmark', bookmark })

Expand Down
Loading

0 comments on commit 2953593

Please sign in to comment.