Skip to content

Commit

Permalink
feat: Add simple meda server
Browse files Browse the repository at this point in the history
please see `README.md`
TODO:
	- [ ] Add to docker-compose
  • Loading branch information
aboueleyes committed May 15, 2024
1 parent 43efcc4 commit 5b52afa
Show file tree
Hide file tree
Showing 28 changed files with 3,394 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mediaserver/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile
node_modules
npm-debug.log
2 changes: 2 additions & 0 deletions mediaserver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
.env
26 changes: 26 additions & 0 deletions mediaserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use latest slim node
FROM node:current-slim

# Set the working directory
WORKDIR /www

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install modules for production
RUN npm install --production

# Copy entire bundle to the working directory
COPY . .

# Create a mount point marked as containing externally mounted volumes.
# Prevents the container's size from increasing with the addition of more static media assets.
# Can be overridden by binding a host directory at runtime.
VOLUME /www/media/static

# Override and expose port 8080
ENV PORT 8080
EXPOSE 8080

# Start the server
CMD ["npm", "run", "start"]
112 changes: 112 additions & 0 deletions mediaserver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# `media-server`

A media server that serves static resources.

## ENV

- `UPLOAD_USER`
- `UPLOAD_PASSWORD`
- `DISCOGS_API_KEY`


## Static Endpoints

For all static resources, this server will attempt to return a relevant resource, or else if the resource does not exist, it will return a default 'placeholder' resource. This prevents clients from having no resource to display at all; clients can make use of this media server's 'describe' endpoint to learn about what resources are available.

### `GET` /static/icons/:icon.png

Returns an icon based on the filename.

`:icon` can be any icon filename.

Example: return an icon with filename 'accept.png'.

```bash
curl --request GET \
--url http://path_to_server/static/icons/accept.png
```

### `GET` /static/resume/:resume.pdf

Returns a resume based on the filename.

`:resume` can be any resume filename.

Example: return a resume with filename 'resume.pdf'.

```bash
curl --request GET \
--url http://path_to_server/static/resume/resume.pdf
```


## Describe

### `GET` /describe

Returns a JSON representation of the media groups.

Example: return JSON containing of all groups present.

```bash
curl --request GET \
--url http://localhost:8910/describe
```

```json
{
"success": true,
"path": "/static/",
"groups": ["icons", "resume"]
}
```

### `GET` /describe/:group

Returns a JSON representation of all the files current present for a given group.

`:group` can be any valid group.

Example: return JSON containing all the media resources for a the exec resource group.

```bash
curl --request GET \
--url http://localhost:8910/describe/exec
```

```json
{
"success": true,
"path": "/static/exec/",
"mimeType": "image/jpeg",
"files": []
}
```

## Upload

Upload and convert media to any of the given static resource group.

All upload routes are protected by basic HTTP auth. The credentials are defined by ENV variables `UPLOAD_USER` and `UPLOAD_PASSWORD`.

### `POST` /upload/:group

POST a resource to a given group, assigning that resource a given filename.

`:group` can be any valid group.

```bash
curl --location 'http://path-to-server/upload/resume/' \
--header 'Authorization: Basic dXNlcjpwYXNz' \
--form 'resource=@"/C:/Users/ibrah/Downloads/Ibrahim_Abou_Elenein_Resume.pdf"' \
--form 'filename="aboueleyes-reume-2"'
```

```json
{
"success": true,
"path": "/static/resume/aboueleyes-reume-2.pdf"
}
```

A resource at `http://path_to_server/static/resume/aboueleyes-reume-2.pdf` will now be available.
20 changes: 20 additions & 0 deletions mediaserver/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Load env variables.
*/
require("dotenv").config();

/**
* Load the server config constants.
*/
const config = require("./src/config");

/**
* Initiate the app.
*/
const app = require("./src/app");

/**
* Define port, and listen...
*/
const port = config.PORT;
app.listen(port, () => console.log("listening on port " + port));
Binary file added mediaserver/media/defaults/raw-banner.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-logo-only.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-logo-only.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-logo-only.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-logo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/defaults/raw-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mediaserver/media/static/icons/aboueleyes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 5b52afa

Please sign in to comment.