-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add homepage routes * delete unnecessary public folder
- Loading branch information
1 parent
3abbc3c
commit 9c2afee
Showing
4 changed files
with
68 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const jwtUtils = require('../utils/jwt-utils') | ||
|
||
// Import classes | ||
const { File, HomepageType } = require('../classes/File.js') | ||
|
||
// Constants | ||
const HOMEPAGE_INDEX_PATH = '' // Empty string | ||
|
||
// Read homepage index file | ||
router.get('/:siteName/homepage', async function(req, res, next) { | ||
try { | ||
const { oauthtoken } = req.cookies | ||
const { access_token } = jwtUtils.verifyToken(oauthtoken) | ||
|
||
const { siteName } = req.params | ||
|
||
const IsomerFile = new File(access_token, siteName) | ||
const homepageType = new HomepageType() | ||
IsomerFile.setFileType(homepageType) | ||
const { sha, content } = await IsomerFile.read(HOMEPAGE_INDEX_PATH) | ||
|
||
// TO-DO: | ||
// Validate content | ||
|
||
res.status(200).json({ content, sha }) | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
}) | ||
|
||
// Update homepage index file | ||
router.post('/:siteName/homepage', async function(req, res, next) { | ||
try { | ||
const { oauthtoken } = req.cookies | ||
const { access_token } = jwtUtils.verifyToken(oauthtoken) | ||
|
||
const { siteName } = req.params | ||
const { content, sha } = req.body | ||
|
||
// TO-DO: | ||
// Validate content | ||
|
||
const IsomerFile = new File(access_token, siteName) | ||
const homepageType = new HomepageType() | ||
IsomerFile.setFileType(homepageType) | ||
const { newSha } = await IsomerFile.update(HOMEPAGE_INDEX_PATH, content, sha) | ||
|
||
res.status(200).json({ content, sha: newSha }) | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
}) | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters