feat: 🎸 Add serializer and adapter for storage bucket (#117)

* feat: 🎸 Add serializer and adapter for storage bucket

✅ Closes: ICU-8358
This commit is contained in:
Zhihe Li authored and GitHub committed 2023-03-15 15:18:02 -04:00
1 parent a28e7810e7
commit 5992829fa2
8 files changed
+175 -2

No files matched your search

@@ -0,0 +1,23 @@
import ApplicationAdapter from './application';
export default class StorageBucketAdapter extends ApplicationAdapter {
/**
* Overrides the default `buildURL` such that on _create_, URLs for records of
* type `plugin` get an extra query parameter `?plugin_name`. All other
* request types behave as normal.
*
* @override
* @param {string} modelName
* @param {string} id
* @return {string} url
* @return {string} requestType
*/
buildURL(modelName, id, snapshot, requestType) {
let url = super.buildURL(...arguments);
const pluginName = snapshot?.attr('plugin')?.name;
if (requestType === 'createRecord' && pluginName) {
url = `${url}?plugin_name=${pluginName}`;
}
return url;
}
}
@@ -72,7 +72,7 @@ export default class GeneratedStorageBucketModel extends BaseModel {
readOnly: true,
isNestedAttribute: true,
})
client_secret_hmac;
secrets_hmac;
@attr('string', {
isNestedSecret: true,
@@ -0,0 +1,13 @@
import ApplicationSerializer from './application';
export default class StorageBucketSerializer extends ApplicationSerializer {
normalize(typeClass, hash, ...rest) {
const normalizedHash = structuredClone(hash);
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
// Remove secret fields
delete normalized.data.attributes.access_key_id;
delete normalized.data.attributes.secret_access_key;
return normalized;
}
}