Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Kloubert committed Jun 11, 2019
1 parent 9dbdf16 commit b5709e0
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.DS_Store
node_modules/
lib/
doc/
src/sandbox.ts
doc/
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ doc
node_modules
.gitignore
src
lib/sandbox.js
tsconfig.json
tslint.json
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Change Log (e-wiki)

- [unreleased]
## 1.0.0

* initial release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# e-wiki

Sets up one or more [wikis](https://github.com/showdownjs/showdown) via [Express](https://expressjs.com/).
Sets up one or more static [wikis](https://github.com/showdownjs/showdown) via [Express](https://expressjs.com/).

## Install

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "e-wiki",
"version": "0.7.0",
"description": "Sets up one or more wikis via Express.",
"version": "1.0.0",
"description": "Sets up one or more static wikis via Express.",
"main": "lib/index.js",
"scripts": {
"build": "(rm -r ./lib || true) && tsc && tsc -d && (mkdir \"./lib/res\") && (cp -r ./src/res/* ./lib/res)",
Expand Down
44 changes: 22 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ export function setupWiki(opts: SetupWikiUIOptions) {
const FOOTER = await loadEJS('footer', TEMPLATE_DATA);

let content = `
<script type="text/javascript">
const MARKDOWN_CONTENT = ${JSON.stringify(
<script type="text/javascript">
const MARKDOWN_CONTENT = ${JSON.stringify(
await fs.readFile(filePath, 'utf8')
)};
</script>
</script>
`;

// Breadcrumb
Expand Down Expand Up @@ -340,36 +340,36 @@ export function setupWiki(opts: SetupWikiUIOptions) {
HEADER + content + FOOTER, 'utf8'
)
);
} else {
// resource file.

res.status(200)
.header('Content-type', mimeType);

if (
!mimeType.startsWith('text/') &&
!mimeType.startsWith('image/') &&
!mimeType.startsWith('video/') &&
!mimeType.endsWith('/json')
) {
res.header('Content-disposition', `attachment; filename="${path.basename(filePath)}"`);
}
}

// resource file ...

fs.createReadStream(filePath)
.pipe(res);
res.status(200)
.header('Content-type', mimeType);

if (
!mimeType.startsWith('text/') &&
!mimeType.startsWith('image/') &&
!mimeType.startsWith('video/') &&
!mimeType.endsWith('/json')
) {
res.header('Content-disposition', `attachment; filename="${path.basename(filePath)}"`);
}

fs.createReadStream(filePath)
.pipe(res);

return;
}
}
}

return res.status(404)
.send();
} catch (e) {
return res.status(500)
.header('Content-type', 'text/plain; charset=utf-8')
.send(Buffer.from(toStringSafe(e), 'utf8'));
}

return res.status(404)
.send();
});
}

0 comments on commit b5709e0

Please sign in to comment.