-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support storage state on extension (#235)
- Loading branch information
Showing
5 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
gopeed.events.onResolve(async function (ctx) { | ||
const key = "key" | ||
const value1 = "value1", value2 = JSON.stringify({a: 1, b: "2"}) | ||
|
||
if (ctx.storage.get(key) !== null) { | ||
throw new Error("storage get null error") | ||
} | ||
ctx.storage.remove(key) | ||
if(ctx.storage.keys().length !== 0) { | ||
throw new Error("storage keys null error") | ||
} | ||
|
||
ctx.storage.set(key, value1) | ||
if (ctx.storage.get(key) !== value1) { | ||
throw new Error("storage put1 error") | ||
} | ||
|
||
ctx.storage.set(key, value2) | ||
if (ctx.storage.get(key) !== value2) { | ||
throw new Error("storage put2 error") | ||
} | ||
|
||
if(ctx.storage.keys().length !== 1) { | ||
throw new Error("storage keys error") | ||
} | ||
|
||
ctx.storage.remove(key) | ||
if (ctx.storage.get(key) !== null) { | ||
throw new Error("storage delete error") | ||
} | ||
|
||
ctx.storage.set(key, value1) | ||
ctx.storage.clear() | ||
if (ctx.storage.get(key) !== null) { | ||
throw new Error("storage clear error") | ||
} | ||
|
||
ctx.res = { | ||
name: "test", | ||
files: Array(2).fill(true).map((_, i) => ({ | ||
name: `test-${i}.txt`, | ||
size: 1024, | ||
req: { | ||
url: ctx.req.url + "/" + i, | ||
} | ||
}), | ||
), | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "basic", | ||
"title": "gopeed extension basic test", | ||
"version": "0.0.1", | ||
"scripts": [ | ||
{ | ||
"event": "onResolve", | ||
"matches": [ | ||
"*://github.com/*" | ||
], | ||
"entry": "index.js" | ||
} | ||
], | ||
"settings": [ | ||
{ | ||
"name": "ua", | ||
"title": "User-Agent", | ||
"type": "string" | ||
} | ||
] | ||
} |