Skip to content

Commit

Permalink
fix: update moveResource route to work on single file only
Browse files Browse the repository at this point in the history
  • Loading branch information
gweiying committed Mar 24, 2021
1 parent bd0cb25 commit 81b4786
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions routes/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ async function renameResource (req, res, next) {
}

// Move resource
async function moveResources (req, res, next) {
async function moveResource (req, res, next) {
const { accessToken } = req
const { siteName, resourceName, newResourceName } = req.params
const { files } = req.body
const { fileName } = req.body

const ResourceRoomInstance = new ResourceRoom(accessToken, siteName)
const resourceRoomName = await ResourceRoomInstance.get()
Expand All @@ -88,18 +88,17 @@ async function moveResources (req, res, next) {
oldIsomerFile.setFileType(oldResourcePageType)
newIsomerFile.setFileType(newResourcePageType)

for (const fileName of files) {
const { content, sha } = await oldIsomerFile.read(fileName)
await oldIsomerFile.delete(fileName, sha)
await newIsomerFile.create(fileName, content)
}
const { content, sha } = await oldIsomerFile.read(fileName)
await oldIsomerFile.delete(fileName, sha)
await newIsomerFile.create(fileName, content)

res.status(200).send('OK')
}

router.get('/:siteName/resources', attachReadRouteHandlerWrapper(listResources))
router.post('/:siteName/resources', attachRollbackRouteHandlerWrapper(createNewResource))
router.delete('/:siteName/resources/:resourceName', attachRollbackRouteHandlerWrapper(deleteResource))
router.post('/:siteName/resources/:resourceName/rename/:newResourceName', attachRollbackRouteHandlerWrapper(renameResource))
router.post('/:siteName/resources/:resourceName/move/:newResourceName', attachRollbackRouteHandlerWrapper(moveResources))
router.post('/:siteName/resources/:resourceName/move/:newResourceName', attachRollbackRouteHandlerWrapper(moveResource))

module.exports = router;

0 comments on commit 81b4786

Please sign in to comment.