Skip to content

Commit

Permalink
FIX: generate unique Device ID and Version ID to get past TickTick Li…
Browse files Browse the repository at this point in the history
…mitation (#166)

Feature: Ribon sync icon not debug dependent any more
Chore: bump version number

Closes #159
Closes #164
  • Loading branch information
thesamim authored Sep 25, 2024
1 parent 24ab3ca commit c10a636
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "tickticksync",
"name": "TickTickSync",
"version": "1.0.33",
"version": "1.0.34",
"minAppVersion": "1.0.0",
"description": "Sync TickTick tasks to Obsidian, and Obsidian tasks to TickTick",
"author": "thesamim",
Expand Down
4 changes: 2 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default class TickTickSync extends Plugin {
//lastLine object {path:line} is saved in lastLines map
this.lastLines = new Map();

if (this.settings.debugMode) {
// if (this.settings.debugMode) {
// This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('sync', 'TickTickSync', async (evt: MouseEvent) => {
// Called when the user clicks the icon.
Expand All @@ -107,7 +107,7 @@ export default class TickTickSync extends Plugin {
// const ribbonIconEl1 = this.addRibbonIcon('check', 'TickTickSync', async (evt: MouseEvent) => {
// // Nothing to see here right now.
// });
}
// }

//Key event monitoring, judging line breaks and deletions
this.registerDomEvent(document, 'keyup', async (evt: KeyboardEvent) => {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "tickticksync",
"name": "TickTickSync",
"version": "1.0.33",
"version": "1.0.34",
"minAppVersion": "1.0.0",
"description": "Sync TickTick tasks to Obsidian, and Obsidian tasks to TickTick",
"author": "thesamim",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tickticksync",
"version": "1.0.33",
"version": "1.0.34",
"description": "Sync TickTick tasks to Obsidian, and Obsidian tasks to TickTick",
"main": "main.js",
"scripts": {
Expand Down
48 changes: 36 additions & 12 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class Tick {
// I **think** it indicates the time of last fetch. This could be useful.
//TODO: in the fullness of time, figure out checkpoint processing to reduce traffic.
private _checkpoint: number;
private deviceVersion: string | undefined;

constructor({ username, password, baseUrl, token, checkPoint }: IoptionsProps) {
this.username = username;
Expand All @@ -66,7 +67,8 @@ export class Tick {
this.inboxProperties = {
id: '', sortOrder: 0
};
this.deviceID = this.generateRandomHex();
this.deviceID = this.generateDeviceID(true);
this.deviceVersion = this.generateVersion(true);
console.log("Device ID: ", this.deviceID);

if (baseUrl) {
Expand Down Expand Up @@ -173,7 +175,7 @@ export class Tick {
return true;
} else {
if (i < 10) {
this._checkpoint = this.getNextCheckPoint();
this.reset()
} else {
return false;
}
Expand Down Expand Up @@ -597,7 +599,7 @@ private createLoginRequestOptions(url: string, body: JSON) {
// 'origin': 'http://ticktick.com',
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/117.0',
'x-device': `{"platform":"web","os":"Windows 10","device":"Firefox 117.0","name":"","version":4576,"id":"${this.deviceID}","channel":"website","campaign":"","websocket":""}`,
'x-device': `{"platform":"web","os":"Windows 10","device":"Firefox 117.0","name":"","version":${this.deviceVersion},"id":"${this.deviceID}","channel":"website","campaign":"","websocket":""}`,
'Cookie': 't='+`${this.token}`+'; AWSALB=pSOIrwzvoncz4ZewmeDJ7PMpbA5nOrji5o1tcb1yXSzeEDKmqlk/maPqPiqTGaXJLQk0yokDm0WtcoxmwemccVHh+sFbA59Mx1MBjBFVV9vACQO5HGpv8eO5pXYL; AWSALBCORS=pSOIrwzvoncz4ZewmeDJ7PMpbA5nOrji5o1tcb1yXSzeEDKmqlk/maPqPiqTGaXJLQk0yokDm0WtcoxmwemccVHh+sFbA59Mx1MBjBFVV9vACQO5HGpv8eO5pXYL'
};
// const myHeaders = new Headers();
Expand All @@ -620,10 +622,11 @@ private createLoginRequestOptions(url: string, body: JSON) {
//For the record, the bloody rules keep changin and we might have to the _csrf_token
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/117.0',
'x-device': `{"platform":"web","os":"Windows 10","device":"Firefox 117.0","name":"","version":4576,"id":"${this.deviceID}","channel":"website","campaign":"","websocket":""}`,
'x-device': `{"platform":"web","os":"Windows 10","device":"Firefox 117.0","name":"","version":${this.deviceVersion},"id":"${this.deviceID}","channel":"website","campaign":"","websocket":""}`,
'Cookie': 't='+`${this.token}`+'; AWSALB=pSOIrwzvoncz4ZewmeDJ7PMpbA5nOrji5o1tcb1yXSzeEDKmqlk/maPqPiqTGaXJLQk0yokDm0WtcoxmwemccVHh+sFbA59Mx1MBjBFVV9vACQO5HGpv8eO5pXYL; AWSALBCORS=pSOIrwzvoncz4ZewmeDJ7PMpbA5nOrji5o1tcb1yXSzeEDKmqlk/maPqPiqTGaXJLQk0yokDm0WtcoxmwemccVHh+sFbA59Mx1MBjBFVV9vACQO5HGpv8eO5pXYL',
't' : `${this.token}`
};
// console.log("headers", headers);
const options: RequestUrlParam = {
method: method,
url: url,
Expand Down Expand Up @@ -680,9 +683,9 @@ private createLoginRequestOptions(url: string, body: JSON) {
//For now: we're not doing the checkpoint bump stuff. If we have more issues...
private getNextCheckPoint() {
let dtDate = new Date(this._checkpoint)
console.log("Date: ", dtDate)
// console.log("Date: ", dtDate)
dtDate.setDate(dtDate.getDate() + 15);
console.log("Date: ", dtDate)
// console.log("Date: ", dtDate)
console.log("Attempted Checkpoint: ", dtDate.getTime())
this._checkpoint = dtDate.getTime();
console.warn("Check point has been changed.", this._checkpoint);
Expand All @@ -696,11 +699,32 @@ private createLoginRequestOptions(url: string, body: JSON) {

return inputString.substring(startIndex, endIndex);
}
private generateRandomHex() {
let retArray = [...Array(20)]
.map(() => Math.floor(Math.random() * 16).toString(16))
.join('');
retArray = '66e9' + retArray;
return retArray;
private generateDeviceID(bForce: boolean) {
let uniqueID = localStorage.getItem("TTS_UniqueID")
if (bForce || !uniqueID) {
uniqueID = crypto.randomUUID().toString();
localStorage.setItem("TTS_UniqueID", uniqueID);
}
console.log("uniqueID: ", uniqueID);
return uniqueID;
}

private generateVersion(bForce: boolean) {
let version = localStorage.getItem("TTS_Version");
if (bForce || !version) {
version = [...Array(4)]
.map(() => Math.floor(Math.random() * 4).toString(4))
.join('');
localStorage.setItem("TTS_Version", version);
}
console.log("Version: ", version);
return version;
}

//Probably overkill, but just to make sure.
private reset() {
this._checkpoint = this.getNextCheckPoint();
this.deviceID = this.generateDeviceID(true);
this.deviceVersion = this.generateVersion(true);
}
}
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"1.0.30": "1.0.0",
"1.0.31": "1.0.0",
"1.0.32": "1.0.0",
"1.0.33": "1.0.0"
"1.0.33": "1.0.0",
"1.0.34": "1.0.0"
}

0 comments on commit c10a636

Please sign in to comment.