forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrateCache.js
81 lines (61 loc) · 2.62 KB
/
migrateCache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import fs, { glob } from "fs/promises";
import path from "path";
const characterName = "eliza";
const newCacheDir = path.resolve(`./data/${characterName}/cache`);
const twitterUserName = "";
// solana
const orderBookPath = "";
const solanaCacheDir = "plugin-solana/**";
const cachedFiles = {
[`tweetcache/${twitterUserName}_cookies.json`]: `twitter/${twitterUserName}/cookies`,
"tweetcache/latest_checked_tweet_id.txt": `twitter/${twitterUserName}/latest_checked_tweet_id`,
"tweetcache/home_timeline.json": `twitter/${twitterUserName}/timeline`,
"tweetcache/tweet_generation_*.txt": "twitter/",
"tweetcache/tweet_generation_*.txt": "twitter/",
"tweetcache/**/*.json": `twitter/tweets/`,
"content_cache/summary_*.txt": "content/discord/",
"content_cache/transcript_*.txt": "content/discord/",
"content_cache/conversation_summary_*.txt": "content/discord/",
"content_cache/**.mp4": "content/video/",
"content_cache/*": "content/",
[orderBookPath]: "solana/orderBook",
[`${solanaCacheDir}/tokenSecurity_`]: "solana/tokens/",
[`${solanaCacheDir}/tokenTradeData_`]: "solana/tokens/",
[`${solanaCacheDir}/dexScreenerData_`]: "solana/tokens/",
[`${solanaCacheDir}/dexScreenerData_search_`]: "solana/tokens/",
[`${solanaCacheDir}/holderList_`]: "solana/tokens/",
};
async function migrate() {
console.log({ newCacheDir });
await fs.mkdir(newCacheDir, { recursive: true });
for (const key in cachedFiles) {
if (!key) continue;
const results = await glob(["./packages/**/" + key]);
console.log({ searching: key });
for await (const result of results) {
if (result.includes("node_modules")) continue;
const filePath = path.resolve("./", result);
const cacheKey = /** @type {string} */ (cachedFiles[key]);
const filename = cacheKey.endsWith("/")
? path.join(
cacheKey,
path.basename(filePath, path.extname(filePath))
)
: cacheKey;
const absolutePath = path.join(newCacheDir, filename) + ".json";
console.log(filePath, absolutePath);
const data = await fs.readFile(filePath, "utf8");
await fs.mkdir(path.dirname(absolutePath), { recursive: true });
await fs.writeFile(
absolutePath,
JSON.stringify({
value: data,
expires: 0,
}),
"utf8"
);
await fs.unlink(filePath);
}
}
}
migrate().catch((err) => console.error(err));