Compare commits

...

6 Commits

Author SHA1 Message Date
Federico Marzocchi
16e94447f7 GitHub workflow for releases (#368)
* GitHub workflow for releases

* avoid renaming

* add workflow for tests

* fix workflow name

* one yaml for all

* fix yaml

* add missing pipe

* add conditional

* also rename that other var

* remove empty version

* print the go version

* add name to step

* add go version when building

* split files

* remove dependency

* delete travis and add badge

* CHANGE NAMES TO LOWER CASE
2021-05-01 19:53:15 +02:00
Stefan Benten
941ec1fe0f Merge pull request #365 from JustAnotherArchivist/disable-download-counter-without-limit
Only increment download counter on files that have a download limit
2021-04-25 21:00:49 +02:00
JustAnotherArchivist
6bd3e97186 Only increment download counter on files that have a download limit
For files that have no limit, there is no reason to track the download counter as its value will never be used anyway. This reduces costs on storage backends that have an operation fee (e.g. AWS S3) or a minimum retention (e.g. Wasabi S3).
2021-04-25 17:47:23 +00:00
Andrea Spacca
31ef712847 Merge pull request #362 from JustAnotherArchivist/fix-metadata-rewrite
Only rewrite metadata file when the download counter changed
2021-04-24 21:23:51 +02:00
JustAnotherArchivist
4daca97f89 Only rewrite metadata file when the download counter changed
Previously, the metadata file would be rewritten even if the download counter stayed the same (i.e. `increaseDownload = false`, previews and HEAD requests). Because the metadata doesn't change in that case, this would simply rewrite the exact same contents needlessly, which may also incur extra costs depending on the storage backend.
2021-04-19 18:37:47 +00:00
Andrea Spacca
69519d8fa4 Unwrap unnecessary bytes.NewReader 2021-03-19 08:25:40 +01:00
6 changed files with 90 additions and 60 deletions

View File

@@ -1,4 +1,4 @@
name: Deploy multi-architecture Docker images for transfer.sh with buildx name: deploy multi-architecture Docker images for transfer.sh with buildx
on: on:
schedule: schedule:

58
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,58 @@
name: release
on:
push:
tags:
- v*
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
GOOS: [ darwin, linux, windows ]
GOARCH: [ amd64 ]
include:
- GOOS: darwin
GOARCH: amd64
suffix: darwin-amd64
- GOOS: windows
GOARCH: amd64
suffix: windows-amd64.exe
- GOOS: linux
GOARCH: amd64
suffix: linux-amd64
- GOOS: linux
GOARCH: arm
suffix: linux-armv7
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: Build ${{ matrix.suffix }} (GOOS=${{ matrix.GOOS }}, GOARCH=${{ matrix.GOARCH }})
env:
GOOS: ${{ matrix.GOOS }}
GOARCH: ${{ matrix.GOARCH }}
run: |
go version
go build -o ./artifacts/transfersh-${GITHUB_REF##*/}-${{ matrix.suffix }}
- uses: actions/upload-artifact@v2
name: Upload artifacts
with:
name: artifacts
path: ./artifacts
release:
runs-on: ubuntu-latest
needs: [ build ]
steps:
- uses: actions/download-artifact@v2
name: Download artifacts
with:
name: artifacts
path: ./artifacts
- name: Publish artifacts
uses: softprops/action-gh-release@v1
with:
files: './artifacts/*'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

27
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,27 @@
name: test
on:
push:
branches:
- "*"
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go_version:
- 1.13.x
- 1.14.x
- 1.15.x
- 1.16.x
name: Test with ${{ matrix.go_version }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go_version }}
- name: Vet and test
run: |
go version
go vet ./...
go test ./...

View File

@@ -1,49 +0,0 @@
language: go
sudo: false
os:
- linux
services:
- docker
go:
- 1.13.x
- 1.14.x
- 1.15.x
- 1.16.x
- tip
env:
global:
- GO111MODULE=on
install:
- go get -t -u -v ./...
- go build -v .
- go vet ./...
script:
- go test ./...
before_deploy:
- mkdir -p release
- "GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags netgo -ldflags '-a -s -w -extldflags -static' -o release/transfersh-$TRAVIS_TAG-linux-amd64"
- "GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 go build -tags netgo -ldflags '-a -s -w -extldflags -static' -o release/transfersh-$TRAVIS_TAG-linux-armv7"
- "GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -tags netgo -ldflags '-a -s -w -extldflags -static' -o release/transfersh-$TRAVIS_TAG-darwin-amd64"
- "GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -tags netgo -ldflags '-a -s -w -extldflags -static' -o release/transfersh-$TRAVIS_TAG-win-amd64.exe"
deploy:
provider: releases
api_key:
secure: cOuMGyvrl/9GX3TZFL+Vq++2Bv5Hlb3VfXSYONfeAj+1AXI3Y+tPruy/XnWpa1MUxkvFuIhea3sUAiKfwhHip9csCmMUhDJtaTU9apsxRkyF/OFrWb7/FlbnqYuAwnp91ImvtSlnubg2VHTjhBA6ycNQF7WZcJEMVMsAtC/nSY4=
file:
- "release/transfersh-$TRAVIS_TAG-linux-amd64"
- "release/transfersh-$TRAVIS_TAG-linux-armv7"
- "release/transfersh-$TRAVIS_TAG-darwin-amd64"
- "release/transfersh-$TRAVIS_TAG-win-amd64.exe"
skip_cleanup: true
on:
tags: true
go: 1.15.x
overwrite: true

View File

@@ -1,4 +1,4 @@
# transfer.sh [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dutchcoders/transfer.sh?utm_source=badge&utm_medium=badge&utm_campaign=&utm_campaign=pr-badge&utm_content=badge) [![Go Report Card](https://goreportcard.com/badge/github.com/dutchcoders/transfer.sh)](https://goreportcard.com/report/github.com/dutchcoders/transfer.sh) [![Docker pulls](https://img.shields.io/docker/pulls/dutchcoders/transfer.sh.svg)](https://hub.docker.com/r/dutchcoders/transfer.sh/) [![Build Status](https://travis-ci.com/dutchcoders/transfer.sh.svg?branch=master)](https://travis-ci.com/dutchcoders/transfer.sh) # transfer.sh [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dutchcoders/transfer.sh?utm_source=badge&utm_medium=badge&utm_campaign=&utm_campaign=pr-badge&utm_content=badge) [![Go Report Card](https://goreportcard.com/badge/github.com/dutchcoders/transfer.sh)](https://goreportcard.com/report/github.com/dutchcoders/transfer.sh) [![Docker pulls](https://img.shields.io/docker/pulls/dutchcoders/transfer.sh.svg)](https://hub.docker.com/r/dutchcoders/transfer.sh/) [![Build Status](https://github.com/dutchcoders/transfer.sh/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/dutchcoders/transfer.sh/actions/workflows/test.yml?query=branch%3Amaster)
Easy and fast file sharing from the command-line. This code contains the server with everything you need to create your own instance. Easy and fast file sharing from the command-line. This code contains the server with everything you need to create your own instance.

View File

@@ -661,13 +661,11 @@ func (s *Server) CheckMetadata(token, filename string, increaseDownload bool) (M
return metadata, errors.New("MaxDownloads expired.") return metadata, errors.New("MaxDownloads expired.")
} else if !metadata.MaxDate.IsZero() && time.Now().After(metadata.MaxDate) { } else if !metadata.MaxDate.IsZero() && time.Now().After(metadata.MaxDate) {
return metadata, errors.New("MaxDate expired.") return metadata, errors.New("MaxDate expired.")
} else { } else if metadata.MaxDownloads != -1 && increaseDownload {
// todo(nl5887): mutex? // todo(nl5887): mutex?
// update number of downloads // update number of downloads
if increaseDownload { metadata.Downloads++
metadata.Downloads++
}
buffer := &bytes.Buffer{} buffer := &bytes.Buffer{}
if err := json.NewEncoder(buffer).Encode(metadata); err != nil { if err := json.NewEncoder(buffer).Encode(metadata); err != nil {
@@ -1011,11 +1009,7 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
if disposition == "inline" && strings.Contains(contentType, "html") { if disposition == "inline" && strings.Contains(contentType, "html") {
reader = ioutil.NopCloser( reader = ioutil.NopCloser(bluemonday.UGCPolicy().SanitizeReader(reader))
bytes.NewReader(
bluemonday.UGCPolicy().
SanitizeReader(reader).
Bytes()))
} }
if w.Header().Get("Range") == "" { if w.Header().Get("Range") == "" {