Skip to content

Commit 7f30c03

Browse files
authored
Merge pull request #278 from cdnjs/sven/remove-r2-file-ext
r2-pump: remove FILE_EXTENSION
2 parents 3d32735 + 7ec0838 commit 7f30c03

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

audit/audit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ func WroteAlgolia(ctx context.Context, pkgName string, currVersion string, lastV
187187
return nil
188188
}
189189

190-
func WroteR2(ctx context.Context, pkgName string, version string, keys []string, ext string) error {
190+
func WroteR2(ctx context.Context, pkgName string, version string, keys []string) error {
191191
content := bytes.NewBufferString("")
192192
fmt.Fprint(content, "Files:\n")
193193
for _, key := range keys {
194194
fmt.Fprintf(content, "- %s\n", key)
195195
}
196196

197-
if err := create(ctx, pkgName, version, "r2-publish/"+ext, content); err != nil {
197+
if err := create(ctx, pkgName, version, "r2-publish", content); err != nil {
198198
return errors.Wrap(err, "could not create audit log file")
199199
}
200200
return nil

functions/r2-pump-http/main.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"log"
1212
"net/http"
1313
"os"
14-
"path/filepath"
1514
"strconv"
1615
"time"
1716

@@ -34,12 +33,6 @@ var (
3433
R2_KEY_SECRET = os.Getenv("R2_KEY_SECRET")
3534
R2_ENDPOINT = os.Getenv("R2_ENDPOINT")
3635

37-
// In an attempt to spread the load across multiple gcp functions, we split
38-
// the upload per file extension (either gz, br or woff2). There should
39-
// be 50/50 for gz and br. Unknown for woff2.
40-
// Example: FILE_EXTENSION=gz
41-
FILE_EXTENSION = os.Getenv("FILE_EXTENSION")
42-
4336
UPLOAD_CONCURENCY = os.Getenv("UPLOAD_CONCURENCY")
4437
)
4538

@@ -97,7 +90,6 @@ func InvokeInner(d InvokePayload, ctx context.Context) error {
9790
}
9891

9992
onFile := func(name string, r io.Reader) error {
100-
ext := filepath.Ext(name)
10193
// remove leading slash
10294
name = name[1:]
10395
key := fmt.Sprintf("%s/%s/%s", pkgName, version, name)
@@ -107,19 +99,17 @@ func InvokeInner(d InvokePayload, ctx context.Context) error {
10799
return errors.Wrap(err, "could not read file")
108100
}
109101

110-
if ext == "."+FILE_EXTENSION {
111-
keys = append(keys, key)
102+
keys = append(keys, key)
112103

113-
meta := newMetadata(len(content))
104+
meta := newMetadata(len(content))
114105

115-
s3Object := s3.PutObjectInput{
116-
Body: bytes.NewReader(content),
117-
Bucket: bucket,
118-
Key: aws.String(key),
119-
Metadata: meta,
120-
}
121-
uploadQueue <- s3Object
106+
s3Object := s3.PutObjectInput{
107+
Body: bytes.NewReader(content),
108+
Bucket: bucket,
109+
Key: aws.String(key),
110+
Metadata: meta,
122111
}
112+
uploadQueue <- s3Object
123113
return nil
124114
}
125115
if err := gcp.Inflate(bytes.NewReader(archive), onFile); err != nil {
@@ -136,7 +126,7 @@ func InvokeInner(d InvokePayload, ctx context.Context) error {
136126
return fmt.Errorf("failed to parse config: %s", err)
137127
}
138128

139-
if err := audit.WroteR2(ctx, pkgName, version, keys, FILE_EXTENSION); err != nil {
129+
if err := audit.WroteR2(ctx, pkgName, version, keys); err != nil {
140130
log.Printf("failed to audit: %s\n", err)
141131
}
142132
if err := metrics.NewUpdatePublishedR2(); err != nil {

0 commit comments

Comments
 (0)