Skip to content

Commit

Permalink
feat: datalayer takes base64 image
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Apr 26, 2022
1 parent a1ad666 commit 5d93fd6
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/config/config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const persistanceFolder = `${homeDir}/.chia/climate-warehouse`;

// Adding this duplicate function here because im having trouble
// importing it in from utils folder
const getConfig = _.memoize(() => {
const getConfig = () => {
const configFile = path.resolve(
`${homeDir}/.chia/climate-warehouse/config.yaml`,
);
Expand Down Expand Up @@ -44,7 +44,7 @@ const getConfig = _.memoize(() => {
} catch (e) {
console.log(e, `Config file not found at ${configFile}`);
}
});
};

module.exports = {
local: {
Expand Down
14 changes: 5 additions & 9 deletions src/controllers/organization.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,17 @@ export const createV2 = async (req, res) => {
orgId: myOrganization.orgUid,
});
} else {
if (!_.get(req, 'files.svg.data')) {
throw new Error('Missing required SVG Icon');
if (!_.get(req, 'files.file.data')) {
throw new Error('Missing required Icon');
}

const { name } = req.body;
const buffer = req.files.svg.data;
const svgIcon = buffer.toString('utf8');

if (!svgIcon.includes('</svg>')) {
throw new Error('Currupted SVG Icon');
}
const buffer = req.files.file.data;
const icon = buffer.toString('base64');

return res.json({
message: 'New organization created successfully.',
orgId: await Organization.createHomeOrganization(name, svgIcon, 'v1'),
orgId: await Organization.createHomeOrganization(name, icon, 'v1'),
});
}
} catch (error) {
Expand Down
9 changes: 0 additions & 9 deletions src/routes/v1/resources/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import joiExpress from 'express-joi-validation';

import { OrganizationController } from '../../../controllers';
import {
newOrganizationSchema,
unsubscribeOrganizationSchema,
subscribeOrganizationSchema,
importOrganizationSchema,
Expand All @@ -18,14 +17,6 @@ OrganizationRouter.get('/', (req, res) => {
return OrganizationController.findAll(req, res);
});

OrganizationRouter.post(
'/',
validator.body(newOrganizationSchema),
(req, res) => {
return OrganizationController.create(req, res);
},
);

OrganizationRouter.delete('/', (req, res) => {
return OrganizationController.resetHomeOrg(req, res);
});
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sync-default-organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const task = new Task('sync-default-organizations', async () => {
try {
await assertDataLayerAvailable();
await assertWalletIsSynced();
if (process.env.USE_SIMULATOR === 'false') {
if (USE_SIMULATOR === 'false') {
Organization.subscribeToDefaultOrganizations();
}
} catch (error) {
Expand Down
6 changes: 1 addition & 5 deletions src/tasks/sync-governance-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ const task = new Task('sync-governance-meta', async () => {
await assertWalletIsSynced();

log('Syncing governance data');
if (
process.env.GOVERANCE_BODY_ID &&
process.env.GOVERNANCE_BODY_IP &&
process.env.GOVERNANCE_BODY_PORT
) {
if (GOVERANCE_BODY_ID && GOVERNANCE_BODY_IP && GOVERNANCE_BODY_PORT) {
Governance.sync();
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sync-organization-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const task = new Task('sync-organization-meta', async () => {
await assertDataLayerAvailable();
await assertWalletIsSynced();
log('Syncing subscribed organizations');
if (process.env.USE_SIMULATOR === 'false') {
if (USE_SIMULATOR === 'false') {
Organization.syncOrganizationMeta();
}
} catch (error) {
Expand Down
6 changes: 2 additions & 4 deletions src/utils/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export const getConfig = _.memoize(() => {
} catch (err) {
// if it still doesnt exist that means we are in an env without write permissions
// so just load the default env
console.log('$$$$$$$$$$$$$$$', process.env.USE_SIMULATOR);
if (process.env.USE_SIMULATOR) {
console.log('################', _.get(process, 'env.USE_SIMULATOR'));
if (typeof process.env.USE_SIMULATOR === 'string') {
defaultConfig.APP.USE_SIMULATOR =
_.get(process, 'env.USE_SIMULATOR', 'false') === 'true';
}
Expand All @@ -32,6 +30,6 @@ export const getConfig = _.memoize(() => {

return yaml.load(fs.readFileSync(configFile, 'utf8'));
} catch (e) {
console.log(`Config file not found at ${configFile}`);
console.log(`Config file not found at ${configFile}`.e);
}
});
6 changes: 3 additions & 3 deletions src/utils/defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"TESTNET_DEFAULT_ORGANIZATIONS": "https://climate-warehouse.s3.us-west-2.amazonaws.com/public/cw-organizations-testnet.json"
},
"GOVERNANCE": {
"GOVERANCE_BODY_ID": "9234ee8a1db6e81e91abbc65961a3c4d2dd97b5404872d9336d60f4ae3057c3d",
"GOVERNANCE_BODY_IP": "71.244.129.72",
"GOVERNANCE_BODY_PORT": 8575
"GOVERANCE_BODY_ID": "8790c347e96eda4266fa5805a16b4baeecf8018433995782555a7b6883fdd868",
"GOVERNANCE_BODY_IP": "35.82.228.204",
"GOVERNANCE_BODY_PORT": 8000
}
}

0 comments on commit 5d93fd6

Please sign in to comment.