-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f4699e7
Showing
8 changed files
with
1,388 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
**/node_modules/ | ||
**/Dockerfile* | ||
**/.dockerignore* | ||
.github | ||
.git | ||
README.md | ||
LICENSE |
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,36 @@ | ||
name: Latest Push | ||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- v* | ||
pull_request: | ||
env: | ||
IMAGE_NAME: ftp-over-http | ||
# | ||
jobs: | ||
push: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
contents: read | ||
# | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Build image | ||
run: docker build . --file Dockerfile.latest --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | ||
|
||
- name: Log in to registry | ||
run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | ||
|
||
- name: Push image | ||
run: | | ||
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
echo IMAGE_ID=$IMAGE_ID | ||
docker tag $IMAGE_NAME $IMAGE_ID:latest-alpine | ||
docker tag $IMAGE_NAME $IMAGE_ID:latest | ||
docker push $IMAGE_ID:latest-alpine | ||
docker push $IMAGE_ID:latest |
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 @@ | ||
node_modules |
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,14 @@ | ||
## Nodejs V18 | ||
FROM node:alpine | ||
|
||
LABEL org.opencontainers.image.source https://github.com/nemrucloud/nodejs-expressjs | ||
|
||
WORKDIR /app | ||
COPY . /app | ||
|
||
RUN npm install -g nodemon | ||
|
||
COPY entrypoint /usr/local/bin/entrypoint | ||
RUN chmod +x /usr/local/bin/entrypoint | ||
|
||
ENTRYPOINT [ "/usr/bin/entrypoint" ] |
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,19 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
cd /app | ||
|
||
if ! [ -f /app/package.json ]; then | ||
npm init -y | ||
fi | ||
|
||
npm install | ||
|
||
# Run command with node if the first argument contains a "-" or is not a system command. The last | ||
# part inside the "{}" is a workaround for the following bug in ash/dash: | ||
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874264 | ||
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then | ||
set -- node "$@" | ||
fi | ||
|
||
exec "$@" |
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,176 @@ | ||
import express from "express"; | ||
import cors from "cors"; | ||
import async from "async"; | ||
import { readFile, rename, unlink, readdir, writeFile, mkdir, rmdir } from "fs/promises"; | ||
import { dirname, join } from "path"; | ||
|
||
const app = express(); | ||
const port = 4000; | ||
|
||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(cors()); | ||
|
||
const dir = "/app"; | ||
|
||
app.get("/files", async (req, res) => { | ||
let results = []; | ||
const list = await readdir(dir, { recursive: true, withFileTypes: true }); | ||
|
||
for (const file of list) { | ||
try { | ||
if (file.isDirectory()) { | ||
continue; | ||
} | ||
if (file.path.includes("node_modules")) { | ||
continue; | ||
} | ||
|
||
results.push({ | ||
path: file.path + "/" + file.name, | ||
content: null, | ||
}); | ||
} catch (error) { } | ||
} | ||
|
||
const CONCURRENCY_LIMIT = 30; | ||
|
||
const responses = await async.mapLimit( | ||
results, | ||
CONCURRENCY_LIMIT, | ||
async (f) => { | ||
return readFile(f.path); | ||
} | ||
); | ||
|
||
for (let index = 0; index < responses.length; index++) { | ||
results[index].content = responses[index].toString(); | ||
} | ||
|
||
return res.json(results); | ||
}); | ||
|
||
app.post("/rm", async (req, res) => { | ||
try { | ||
const { fileName } = req.body; | ||
if (!fileName) return res.json({ status: false, message: "Please enter file name." }); | ||
|
||
const path = join(dir, dosyaAdi); | ||
|
||
await unlink(path); | ||
|
||
res.json({ status: true }); | ||
} catch (error) { | ||
return res.json({ status: false, error }); | ||
} | ||
}); | ||
|
||
app.post("/rmdir", async (req, res) => { | ||
try { | ||
const { folder } = req.body; | ||
if (!folder) return res.json({ status: false, message: "Please enter folder name." }); | ||
|
||
if (folder.includes("..")) { | ||
return res.json({ status: false, message: "Please enter valid file name.", }); | ||
} | ||
|
||
const path = join(dir, folder); | ||
|
||
await rmdir(path, { recursive: true, force: true }); | ||
|
||
res.json({ status: true }); | ||
} catch (error) { | ||
return res.json({ status: false, error }); | ||
} | ||
}); | ||
|
||
app.get("/read", async (req, res) => { | ||
try { | ||
const { fileName } = req.body; | ||
|
||
if (fileName.includes("..")) { | ||
return res.json({ status: false, message: "Please enter valid file name.", }); | ||
} | ||
|
||
const path = join(dir, fileName); | ||
const content = await readFile(path, { encoding: "utf-8" }); | ||
|
||
res.json({ | ||
status: true, | ||
content, | ||
}); | ||
} catch (error) { | ||
return res.json({ status: false, error }); | ||
} | ||
}); | ||
|
||
app.post("/move", async (req, res) => { | ||
try { | ||
const { oldName, newName } = req.body; | ||
|
||
if (!oldName || !oldName) { | ||
return res.json({ status: false, message: "Please enter file name and new file name.", }); | ||
} | ||
|
||
if (oldName.includes("..") || newName.includes("..")) { | ||
return res.json({ status: false, message: "Please enter valid file name and new file name.", }); | ||
} | ||
|
||
const oldPath = join(dir, oldName); | ||
const newPath = join(dir, newName); | ||
|
||
await mkdir(dirname(newPath), { recursive: true }) | ||
|
||
await rename(oldPath, newPath); | ||
|
||
return res.json({ status: true }); | ||
} catch (error) { | ||
return res.json({ status: false, error }); | ||
} | ||
}); | ||
|
||
app.post("/put", async (req, res) => { | ||
try { | ||
const { filename, content } = req.body; | ||
|
||
if (!filename) return res.json({ status: false, message: "Please enter a filename.", }); | ||
|
||
if (filename.includes("..")) { | ||
return res.json({ status: false, message: "Please enter valid file name and new file name.", }); | ||
} | ||
|
||
const filePath = join(dir, filename); | ||
|
||
await mkdir(dirname(filePath), { recursive: true }) | ||
|
||
await writeFile(filePath, content); | ||
|
||
return res.json({ status: true }); | ||
} catch (error) { | ||
return res.json({ status: false, error }); | ||
} | ||
}); | ||
|
||
app.post("/mkdir", async (req, res) => { | ||
try { | ||
const { folder } = req.body; | ||
|
||
if (!folder) return res.json({ status: false, message: "Please enter a folder name.", }); | ||
|
||
if (folder.includes("..")) { | ||
return res.json({ status: false, message: "Please enter valid file name and new file name.", }); | ||
} | ||
|
||
const folderPath = join(dir, folder); | ||
|
||
await mkdir(dirname(folderPath), { recursive: true }) | ||
|
||
return res.json({ status: true }); | ||
} catch (error) { | ||
return res.json({ status: false, error }); | ||
} | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Listening ::${port}`); | ||
}); |
Oops, something went wrong.