Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 8a5beaa

Browse files
committed
feat(UserPasteStore): implement store()
1 parent d005ad5 commit 8a5beaa

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/struct/stores/UserPasteStore.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ export default class UserPasteStore extends Map {
3434
for (const [k, v] of entries) this.set(k, v)
3535
}
3636

37+
/**
38+
* Store and get a paste by its key.
39+
* @param data The data obtained from the API
40+
* @param key The paste's key
41+
*/
42+
store(data: any, key: string = data.key): Paste {
43+
let existing = this.get(key)
44+
if (existing) {
45+
existing._apply(data)
46+
} else {
47+
existing = new Paste(this.client, data)
48+
this.set(key, existing)
49+
}
50+
return existing
51+
}
52+
3753
/**
3854
* Fetch this user's pastes, and store them in the cache.
3955
* @param max The maximum number of pastes to fetch
@@ -57,7 +73,7 @@ export default class UserPasteStore extends Map {
5773

5874
for (const xml of xmls) {
5975
const parsed = await parseStringPromise(xml)
60-
const paste = new Paste(this.client, {
76+
this.store({
6177
key: parsed.paste.paste_key[0],
6278
date: new Date(Number(parsed.paste.paste_date[0]) * 1000),
6379
title: parsed.paste.paste_title[0],
@@ -68,14 +84,13 @@ export default class UserPasteStore extends Map {
6884
format: parsed.paste.paste_format_short[0],
6985
hits: Number(parsed.paste.paste_hits[0])
7086
})
71-
this.set(paste.key, paste)
7287
}
7388

7489
return this
7590
}
7691

7792
set(key: string, paste: Paste) {
78-
this.client.pastes.set(key, paste)
93+
this.client.pastes.store(paste)
7994
super.set(key, paste)
8095
return this
8196
}

0 commit comments

Comments
 (0)