-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: auto install bundle on instagoric #49
base: main
Are you sure you want to change the base?
Conversation
9ecfb3d
to
d84df96
Compare
`); | ||
}); | ||
|
||
publicapp.post('/install-bundle', upload.single('file') ,async (req, res) => { |
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.
publicapp.post('/install-bundle', upload.single('file') ,async (req, res) => { | |
publicapp.post('/install-bundle', upload.single('file'), async (req, res) => { |
const bundle = (req.file?.filename); | ||
const result = await $`\ | ||
${agBinary} tx swingset install-bundle --compress "@uploads/${bundle}" \ | ||
--from ${FAUCET_KEYNAME} --keyring-backend=test --keyring-dir=${agoricHome} --gas=auto \ | ||
--chain-id=${chainId} -b block --yes | ||
`; |
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.
As we have used optional chaining, then req.file?.filename
then bundle can be undefined. In that case, let's avoid sending tx
to chain.
Can we have a quick working clip on PR? |
</body> | ||
</html> | ||
`); | ||
}); |
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’s better to serve static HTML from a separate file.
publicapp.get('/install-bundle', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
body: formData | ||
}) | ||
.then(data => { | ||
alert('File uploaded successfully!'); |
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.
I think we should check the response status before declaring the API request as a success.
.then(response => {
if (!response.ok) {
throw new Error('Failed to upload file. Server responded with status ' + response.status);
}
return response.json();
})
}); | ||
|
||
publicapp.post('/install-bundle', upload.single('file'), async (req, res) => { | ||
// Getting file from request and storing as temp file |
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.
get
and post
have the same endpoint name. Do you think we should have distinct names?
|
||
<form id="uploadForm" action="/install-bundle" method="POST" enctype="multipart/form-data"> | ||
<input type="file" name="file" id="fileInput" required> | ||
<br><br> |
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.
Is there a specific type of file we take as input? Should we have validation for it in the frontend or backend? Maybe enforce file size limitations as well?
|
||
<h1>Upload a File</h1> | ||
|
||
<form id="uploadForm" action="/install-bundle" method="POST" enctype="multipart/form-data"> |
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.
Why do we need to define action
and method
here if we are overriding the default browser behavior?
const result = await $`\ | ||
${agBinary} tx swingset install-bundle --compress "@uploads/${bundle}" \ | ||
--from ${FAUCET_KEYNAME} --keyring-backend=test --keyring-dir=${agoricHome} --gas=auto \ | ||
--chain-id=${chainId} -b block --yes |
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.
Using -b block
could show false positive error messages to the user
Demo video:
Screen.Recording.2024-09-11.at.8.20.06.PM.mov
Instructions to run:
in agoric-sdk
bases/shared/instagoric-server/server.js
file with this codecode
in instagoric repo: