-
-
Notifications
You must be signed in to change notification settings - Fork 272
Create firebasedb.js #2087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Create firebasedb.js #2087
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a quick review going over TW extension best practices, I don't have time to do a full in-depth functionality review. To wrap up: use Scratch.translate
and Scratch.Cast
where necessary.
@@ -0,0 +1,187 @@ | |||
// Name: FirebaseDB | |||
// ID: firebasedb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ID should include your username in both header metadata and the getInfo ID
extensions/firebasedb.js
Outdated
color1: "#fea631", | ||
menuIconURI: icon, | ||
blocks: [ | ||
{blockType: Scratch.BlockType.LABEL, text: "Made by @logise on Discord"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for consistent formatting why can't you open this structure up like the other blocks?
extensions/firebasedb.js
Outdated
getInfo() { | ||
return { | ||
id: "FirebaseDB", | ||
name: "Firebase DB", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix all of the lint errors you can just use Scratch.translate()
on the extension and block names.
extensions/firebasedb.js
Outdated
{ | ||
opcode: "setKey", | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: "set key [KEY] to value [VALUE]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should also translate the block text
extensions/firebasedb.js
Outdated
}; | ||
} | ||
|
||
async delay() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint is returning Async method 'delay' has no 'await' expression
. Avoid putting async
before the extension's block functions, rather just put an asynchronous function inside them
extensions/firebasedb.js
Outdated
await this.delay(); | ||
const { KEY, VALUE } = args; | ||
if (VALUE.length > 8000) return; | ||
await fetch(`${this.api}/pin/${encodeURIComponent(KEY)}.json`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Scratch.fetch() instead of fetch()
extensions/firebasedb.js
Outdated
async deriveKey(password, salt) { | ||
const enc = new TextEncoder(); | ||
const keyMaterial = await crypto.subtle.importKey( | ||
"raw", enc.encode(password), "PBKDF2", false, ["deriveKey"] | ||
); | ||
return await crypto.subtle.deriveKey( | ||
{ | ||
name: "PBKDF2", | ||
salt, | ||
iterations: 100000, | ||
hash: "SHA-256" | ||
}, | ||
keyMaterial, | ||
{ name: "AES-GCM", length: 256 }, | ||
false, | ||
["encrypt", "decrypt"] | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like all of the block functions are async for interacting with the database server. Is it necessary to do it like this or can you put an asynchronous function inside all of them? Also, you might want to include documentation noting this because I don't remember if the script pauses until each async block finishes executing or continues while the asyncs are still executing
extensions/firebasedb.js
Outdated
|
||
async getKeyWithPassword(args) { | ||
await this.delay(); | ||
const { KEY, PASSWORD } = args; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking you should use Scratch.Cast() on all of your arguments to avoid weird quirks... this goes for all blocks too
!format |
1 similar comment
!format |
No description provided.