Skip to content
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

Fix: encode/decode homepage content #151

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions routes/homepage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require('express');
const router = express.Router();
const base64 = require('base-64')

// Import middleware
const {
Expand All @@ -22,7 +23,8 @@ async function readHomepage (req, res, next) {
const IsomerFile = new File(accessToken, siteName)
const homepageType = new HomepageType()
IsomerFile.setFileType(homepageType)
const { sha, content } = await IsomerFile.read(HOMEPAGE_INDEX_PATH)
const { sha, content: encodedContent } = await IsomerFile.read(HOMEPAGE_INDEX_PATH)
const content = Base64.decode(encodedContent)

// TO-DO:
// Validate content
Expand All @@ -43,7 +45,7 @@ async function updateHomepage (req, res, next) {
const IsomerFile = new File(accessToken, siteName)
const homepageType = new HomepageType()
IsomerFile.setFileType(homepageType)
const { newSha } = await IsomerFile.update(HOMEPAGE_INDEX_PATH, content, sha)
const { newSha } = await IsomerFile.update(HOMEPAGE_INDEX_PATH, Base64.encode(content), sha)

res.status(200).json({ content, sha: newSha })
}
Expand Down