Skip to content

Commit

Permalink
fix #36
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed May 29, 2024
1 parent c315005 commit 2071c8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
29 changes: 17 additions & 12 deletions server/datastores/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ module.exports = class S3Datastore extends Datastore {

const users = await this.getUsers();

console.log("retrieved users : " + users)

await instance.send(new PutObjectCommand({
Bucket,
Key: 'users.json',
Expand All @@ -153,28 +151,35 @@ module.exports = class S3Datastore extends Datastore {
createUserIfNotExists = async (email) => {
const { instance, Bucket } = this.#state;;

console.log("attempt to create user : " + email)
// console.log("attempt to create user : " + email)
try {
const res = await instance.send(new HeadObjectCommand({
Bucket,
Key: `${format(email)}.json`
}))
console.log('user file has been retrieved : ' + email);
// console.log('user file has been retrieved : ' + email);
} catch (err) {
console.log('user file not found : ' + email);
// console.log('user file not found : ' + email);
await this.#addUser(format(email))
}
}

getUsers = () => {
getUsers = async () => {
const { instance, Bucket } = this.#state;

return instance.send(new GetObjectCommand({
Bucket,
Key: 'users.json'
}))
.then(data => new fetch.Response(data.Body).json())
.catch(err => logger.error(err))
try {
const rawData = await instance.send(new GetObjectCommand({
Bucket,
Key: 'users.json'
}))
return new fetch.Response(rawData.Body).json()
} catch (err) {
if (err.$metadata.httpStatusCode === 404 && err.Code === "NoSuchKey") {
return []
} else {
throw err
}
}
}

updateUser = (email, content) => {
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wasmo",
"version": "1.2.0",
"version": "1.2.1",
"main": "index.js",
"license": "MIT",
"scripts": {
Expand Down

0 comments on commit 2071c8a

Please sign in to comment.