From e52ddbdc12a142bc05288772e9e4a7d7107fd52e Mon Sep 17 00:00:00 2001 From: PorridgePi Date: Mon, 18 Sep 2023 13:44:02 +0800 Subject: [PATCH] DayOne: feat: Update with Proxyman compatibility and new JSON --- DayOne.js | 354 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 300 insertions(+), 54 deletions(-) diff --git a/DayOne.js b/DayOne.js index 978d5cc..fcc59a9 100644 --- a/DayOne.js +++ b/DayOne.js @@ -1,60 +1,306 @@ -const featureBundle = { - "bundleName": "premium", - "reason": "purchase", - "features": [{ - "name": "imagesPerEntry", - "limit": 30, - "canUpgrade": false - }, { - "name": "journalLimit", - "limit": 100, - "canUpgrade": false - }, { - "name": "audioPerEntry", - "limit": 10, - "canUpgrade": false - }, { - "name": "backup", - "limit": null, - "canUpgrade": false - }, { - "name": "sync", - "limit": null, - "canUpgrade": false - }, { - "name": "syncMac", - "limit": null, - "canUpgrade": false - }, { - "name": "printingDiscount", - "limit": null, - "canUpgrade": false - }, { - "name": "prioritySupport", - "limit": null, - "canUpgrade": false - }] +let isPremium = true; // if false, will use plus + +let feature_enrollments = [{ + "id": 0, + "feature": "publish", + "createDate": "2011-11-11T00:00:00.000Z", + "status": "active", + "isActive": true + }, + { + "id": 0, + "feature": "backup", + "createDate": "2011-11-11T00:00:00.000Z", + "status": "active", + "isActive": true + }, + { + "id": 0, + "feature": "sync", + "createDate": "2011-11-11T00:00:00.000Z", + "status": "active", + "isActive": true + } +] + +let subscription = { + "premium": isPremium, + "plus_on_ios": true, + "plus_on_mac": true, + "source": [ + "Receipt" + ], + "auto_renew": false, + "is_trial": false, + "expires": (isPremium ? "2099-12-31T23:59:59.999Z" : null), + "product_id": (isPremium ? "com.bloombuilt.dayoneios.subscription.premium.yearly" : null), + "is_eligible_for_trial": true, + "is_in_billing_retry_period": false } -const featureEnrollments_Sync = { - "id": 0, - "feature": "sync", - "createDate": "2011-11-11T00:00:00.000Z", - "status": "active", - "isActive": true +let bundle = { + "bundleName": (isPremium ? "premium" : "grandfathered"), + "reason": "purchase", + "features": [{ + "name": "imagesPerEntry", + "limit": (isPremium ? 30 : 10), + "canUpgrade": !isPremium + }, + { + "name": "imagesPerSharedEntry", + "limit": 30, + "canUpgrade": false + }, + { + "name": "journalLimit", + "limit": (isPremium ? 200 : 10), + "canUpgrade": !isPremium + }, + ...(isPremium ? [{ + "name": "audioPerEntry", + "limit": 10, + "canUpgrade": false + }] : []), + { + "name": "sync", + "limit": null, + "canUpgrade": false + }, + { + "name": "backup", + "limit": null, + "canUpgrade": false + }, + ...(!isPremium ? [{ + "name": "discountedSubscription", + "limit": null, + "canUpgrade": false + }] : []), + ...(isPremium ? [{ + "name": "printingDiscount", + "limit": null, + "canUpgrade": false + }, { + "name": "prioritySupport", + "limit": null, + "canUpgrade": false + }, { + "name": "drawingsPerEntry", + "limit": 30, + "canUpgrade": false + }, { + "name": "scanToPDF", + "limit": 30, + "canUpgrade": false + }, { + "name": "videosPerEntry", + "limit": 30, + "canUpgrade": false + }, { + "name": "journalViaSMS", + "limit": null, + "canUpgrade": false + }] : []) + ], + "featuresFull": [{ + "name": "journalLimit", + "limit": (isPremium ? 200 : 10), + "canUpgrade": !isPremium + }, + { + "name": "backup", + "enabled": true, + "canUpgrade": false + }, + { + "name": "sync", + "enabled": true, + "canUpgrade": false + }, + { + "name": "discountedSubscription", + "enabled": !isPremium, + "canUpgrade": false + }, + { + "name": "printingDiscount", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "prioritySupport", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "scanToPDF", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "attachmentsPerEntry", + "limit": (isPremium ? 30 : 10), + "canUpgrade": !isPremium + }, + { + "name": "journalViaSMS", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "canAttachPhoto", + "enabled": true, + "canUpgrade": false + }, + { + "name": "canAttachVideo", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "canAttachAudio", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "canAttachDrawing", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "canAttachPDF", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "canAttachSharedPhoto", + "enabled": true, + "canUpgrade": false + }, + { + "name": "canAttachSharedVideo", + "enabled": true, + "canUpgrade": false + }, + { + "name": "canAttachSharedAudio", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "canAttachSharedDrawing", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "canAttachSharedPDF", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "attachmentsPerSharedEntry", + "limit": 30, + "canUpgrade": false + }, + { + "name": "instagram", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "ifttt", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "colors", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "emailToJournal", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "appIcons", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "moonPhase", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "foursquareNearbyVenues", + "enabled": isPremium, + "canUpgrade": !isPremium + }, + { + "name": "createSharedJournal", + "enabled": isPremium, + "canUpgrade": !isPremium + } + ] } -var bodyOG = $response.body; -var body = JSON.parse(bodyOG); +let account_status = { + "subscriptionName": (isPremium ? "premium" : "grandfathered"), + "bundleReason": "purchase", + "expirationDate": (isPremium ? 4102415999999 : null), + "giftedByName": null, + "source": (isPremium ? "receipt" : "min") +} -body["featureBundle"] = featureBundle -body["subscription"]["premium"] = true -body["subscription"]["plus_on_mac"] = true -body["subscription"]["source"] = ["Receipt"] -body["subscription"]["auto_renew"] = true -body["subscription"]["expires"] = "2021-06-20T14:28:46.000Z" -body["subscription"]["product_id"] = "com.bloombuilt.dayoneios.subscription.premium.yearly_discounted_trial" +async function onResponse(context, url, request, response) { + response.headers["Content-Type"] = "application/json"; + response.statusCode = 200; + response.statusPhrase = "OK"; -bodyOG = JSON.stringify(body); -console.log(bodyOG); -$done(bodyOG); + let body = response.body; + + if (url.includes("account-status")) { // /account-status + body = account_status; + } else { // /users OR /v2/users/receipt + body.subscription = subscription; + if (url.includes("v2")) { // /v2/users/receipt + body.bundle = bundle; + } else { // /users + body.featureBundle = bundle; + body.featureEnrollments = feature_enrollments; + } + } + + response.body = body; + return response; +} + + +const isSurge = typeof $httpClient != "undefined"; +const isQuanX = typeof $task != "undefined"; +const isLoon = typeof $loon != "undefined"; +const isJSBox = typeof $app != "undefined" && typeof $http != "undefined"; +const isNode = typeof require == "function" && !isJSBox; + +if (isSurge || isQuanX) { + url = $request.url; + + $request.body = typeof $request.body != "undefined" ? JSON.parse($request.body) : {}; + $response.body = typeof $response.body != "undefined" ? JSON.parse($response.body) : {}; + + response = onResponse(null, url, $request, $response); + + if (isQuanX) { + $request.status = "HTTP/1.1 " + $request.statusCode + " " + $request.statusPhrase; + $response.status = "HTTP/1.1 " + $response.statusCode + " " + $response.statusPhrase; + $request.body = JSON.stringify($request.body); + $response.body = JSON.stringify($response.body); + } + + $done({ + status: $response.status, + headers: $response.headers, + body: $response.body + }); +}