The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | const { readFileSync } = require("node:fs"); |
| 2 | |
| 3 | function readClient(value, now = Date.now()) { |
| 4 | try { |
| 5 | const record = JSON.parse(value); |
| 6 | return typeof record?.link === "string" && Date.parse(record.expiresAt) > now |
| 7 | ? record.link |
| 8 | : ""; |
| 9 | } catch { |
| 10 | return ""; |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | function createRecord(link, profile) { |
| 15 | const expiration = /<key>ExpirationDate<\/key>\s*<date>([^<]+)<\/date>/.exec(profile)?.[1]; |
| 16 | if (!expiration || !Number.isFinite(Date.parse(expiration))) { |
| 17 | throw new Error("The provisioning profile has no valid ExpirationDate."); |
| 18 | } |
| 19 | return JSON.stringify({ link, expiresAt: new Date(expiration).toISOString() }); |
| 20 | } |
| 21 | |
| 22 | if (require.main === module) { |
| 23 | if (process.argv[2] === "read") { |
| 24 | process.stdout.write(readClient(readFileSync(0, "utf8"))); |
| 25 | } else if (process.argv[2] === "create") { |
| 26 | process.stdout.write(createRecord(process.argv[3], readFileSync(process.argv[4], "utf8"))); |
| 27 | } else { |
| 28 | throw new Error("Expected read or create."); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | module.exports = { createRecord, readClient }; |