Skip to content
Snippets Groups Projects
Commit c2099e06 authored by Dean's avatar Dean
Browse files

bump version to 1.0.1, change default bucket ID to public, change object schema

parent 10f249b4
No related branches found
No related tags found
No related merge requests found
......@@ -132,7 +132,7 @@ func main() {
log.Info("Attempting to listen on " + listenAddr)
server := &fasthttp.Server{
Handler: h,
Name: "whats-this/cdn-origin/1.0.0",
Name: "whats-this/cdn-origin/1.0.1",
ReadBufferSize: 1024 * 6, // 6 KB
ReadTimeout: time.Minute * 30,
WriteTimeout: time.Minute * 30,
......@@ -167,7 +167,9 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
var content_type sql.NullString
var long_url sql.NullString
var object_type int
err := db.QueryRow(`SELECT backend_file_id, content_type, long_url, "type" FROM objects WHERE bucket='0' AND "key"=$1 LIMIT 1`, string(ctx.Path())).Scan(&backend_file_id, &content_type, &long_url, &object_type)
err := db.QueryRow(
`SELECT backend_file_id, content_type, long_url, "type" FROM objects WHERE bucket_key=$1 LIMIT 1`,
fmt.Sprintf("public%s", ctx.Path())).Scan(&backend_file_id, &content_type, &long_url, &object_type)
switch {
case err == sql.ErrNoRows:
ctx.SetStatusCode(fasthttp.StatusNotFound)
......
-- "objects" table schema
CREATE TABLE IF NOT EXISTS objects (
id VARCHAR(20) PRIMARY KEY NOT NULL, -- uint64 Twitter snowflake ID (primary)
bucket VARCHAR(20) NOT NULL, -- uint64 bucket ID (0 = public)
"key" VARCHAR(1024) NOT NULL, -- Full bucket path to file (including directory)
bucket_key VARCHAR(1088) NOT NULL UNIQUE, -- bucket + key (unique)
bucket VARCHAR(20) NOT NULL, -- uint64 bucket ID ("public" for public bucket)
"key" VARCHAR(1024) NOT NULL, -- Full bucket path to file (including directory)
dir VARCHAR(1024) NOT NULL, -- Directory of file (with trailing slash)
"type" integer NOT NULL DEFAULT 0, -- Object type enumerable (0 = file, 1 = short_url)
backend_file_id VARCHAR(33) DEFAULT NULL, -- SeaweedFS file ID (only when object.type == 0)
long_url VARCHAR(1024) DEFAULT NULL, -- Long URL (only when object.type == 1)
content_type VARCHAR(255) DEFAULT 'application/octet-stream', -- Content-Type of file
content_length INT DEFAULT NULL, -- Content-Length of file
auth_hash VARCHAR(64) DEFAULT NULL, -- Authentication hash: sha256(user.id + password + object.id)
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- File creation timestamp
md5_hash VARCHAR(32) DEFAULT NULL -- MD5 hash of file contents (or long URL)
);
-- Test file object: /index.md
INSERT INTO objects (id, bucket, key, bucket_key, type, backend_file_id, content_type, md5_hash) VALUES (
'0',
'0',
INSERT INTO objects (bucket_key, bucket, key, dir, type, backend_file_id, content_type, content_length, md5_hash) VALUES (
'public/index.txt',
'public',
'/index.txt',
'0/index.txt',
'/',
0,
'1,020c3fd6ab',
'text/plain',
0,
'e2a81ac6617d7963bda5155239b4b262'
);
-- Test short_url object: /short_link
INSERT INTO objects (id, bucket, key, bucket_key, type, long_url, content_type, md5_hash) VALUES (
'1',
'0',
INSERT INTO objects (bucket_key, bucket, key, dir, type, long_url, content_type) VALUES (
'public/short_path',
'public',
'/short_path',
'0/short_path',
'/',
1,
'https://google.com',
NULL,
'99999ebcfdb78df077ad2727fd00969f'
NULL
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment