Compare commits

...

8 Commits

Author SHA1 Message Date
73559fde88 version bump
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-08 22:11:46 +02:00
d303ec9154 added docker to README 2022-06-08 22:09:18 +02:00
de5d5a2344 added example script to upload and share files
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-08 21:57:17 +02:00
2ebe95e9f8 added workdir to dockerfile
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-08 12:50:38 +02:00
741256c1e4 added expose port to Dockerfile
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-08 12:38:45 +02:00
db3a257ecd added PDF opener 2022-06-08 12:02:09 +02:00
c83094266b fixed golang version in drone
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-08 11:13:17 +02:00
80a99aa9c2 added tests to drone
Some checks failed
continuous-integration/drone/push Build is failing
2022-06-08 11:10:29 +02:00
8 changed files with 74 additions and 6 deletions

View File

@@ -3,6 +3,10 @@ type: docker
name: default name: default
steps: steps:
- name: test
image: golang:latest
commands:
- make test
- name: docker - name: docker
image: plugins/docker image: plugins/docker
settings: settings:

View File

@@ -18,4 +18,8 @@ FROM gcr.io/distroless/base-debian10
COPY --from=gobuild /app/build/s3share /app/s3share COPY --from=gobuild /app/build/s3share /app/s3share
COPY --from=jsbuild /app/build/public /app/public COPY --from=jsbuild /app/build/public /app/public
EXPOSE 3000
WORKDIR /app
ENTRYPOINT [ "/app/s3share" ] ENTRYPOINT [ "/app/s3share" ]

View File

@@ -25,6 +25,10 @@ deps: node_modules
node_modules: node_modules:
npm install npm install
.PHONY: test
test:
go test -v ./...
.PHONY:clean .PHONY:clean
clean: clean:
rm -rf $(BUILD_DIR) && rm -rf public/build/ rm -rf $(BUILD_DIR) && rm -rf public/build/

View File

@@ -20,6 +20,10 @@ S3Share requires two things:
- a s3 bucket with read access - a s3 bucket with read access
- a sql database - a sql database
## Docker
The docker image is available at [Dockerhub](https://hub.docker.com/r/djeeberjr/s3share). There is also a [docker-compose](docker-compose.yml) file that can be used as an example.
# Synopsis # Synopsis
``` ```

View File

@@ -19,8 +19,7 @@ type args struct {
} }
func (args) Version() string { func (args) Version() string {
// TODO return "s3share 1.0"
return "s3share 0.1"
} }
func main() { func main() {

39
share.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env sh
set -e
# This is an example on how i use this to upload and share files.
# This is tested with minio.
# You may need to change some things in here to fit your needs.
# Change these variables
S3_BUCKET="bucketname"
S3_ACCESS_KEY="accesskey"
S3_SECRET_KEY="secretkey"
S3_ENDPOINT="s3.example.com"
ENDPOINT="https://share.example.com"
API_USERNAME="admin"
API_PASSWORD="hunter2"
# Dont touch the things below
UPLOAD_FILE="$1"
if test -n "$1"; then
UPLOAD_FILE=$1
elif test ! -t 0; then
read -r UPLOAD_FILE
else
>&2 echo "Provide a file"
echo "Usage: $0 <file>"
exit 1
fi
UPLOAD_FILENAME=$(basename "$UPLOAD_FILE")
s3cmd -q -s --host "$S3_ENDPOINT" --host-bucket "$S3_ENDPOINT" --access_key "$S3_ACCESS_KEY" --secret_key "$S3_SECRET_KEY" put "$UPLOAD_FILE" s3://$S3_BUCKET/
SLUG=$(curl -s -u "$API_USERNAME:$API_PASSWORD" -X POST --header "Content-Type: application/json" \
--data "{\"key\":\"$UPLOAD_FILENAME\"}" \
"$ENDPOINT/api/share" | jq -r ".slug")
printf "%s/%s\n" "$ENDPOINT" "$SLUG"

View File

@@ -13,7 +13,7 @@ export default function getComponentForShare(contentType: string, filename: stri
} }
if (contentType.startsWith("application/pdf")) { if (contentType.startsWith("application/pdf")) {
return import("./opener/Default.svelte"); return import("./opener/PDF.svelte");
} }
if (contentType.startsWith("text/")) { if (contentType.startsWith("text/")) {
@@ -25,7 +25,7 @@ export default function getComponentForShare(contentType: string, filename: stri
case "application/ld+json": case "application/ld+json":
case "application/xhtml+xml": case "application/xhtml+xml":
case "application/xml": case "application/xml":
return import("./opener/Default.svelte"); return import("./opener/Text.svelte");
case "application/ogg": case "application/ogg":
return import("./opener/Default.svelte"); return import("./opener/Default.svelte");
} }
@@ -56,13 +56,13 @@ export default function getComponentForShare(contentType: string, filename: stri
case "flac": case "flac":
return import("./opener/Default.svelte"); return import("./opener/Default.svelte");
case "pdf": case "pdf":
return import("./opener/Default.svelte"); return import("./opener/PDF.svelte");
case "txt": case "txt":
case "md": case "md":
case "markdown": case "markdown":
return import("./opener/Default.svelte"); return import("./opener/Default.svelte");
} }
return import("./opener/Text.svelte"); return import("./opener/Default.svelte");
} }

14
web/opener/PDF.svelte Normal file
View File

@@ -0,0 +1,14 @@
<script lang="ts">
export let contentType: string;
export let filename: string;
export let slug: string;
</script>
<iframe src="/s/{slug}.pdf" title="{filename}" frameborder="0"></iframe>
<style>
iframe{
min-width: 100%;
height: 90vh;
}
</style>