-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow UTF-8 encoded object names
- Loading branch information
Showing
12 changed files
with
563 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
ALTER TABLE "storage"."objects" | ||
ADD CONSTRAINT objects_name_check | ||
CHECK (name SIMILAR TO '[\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x00010000-\x0010ffff]+'); | ||
|
||
CREATE OR REPLACE FUNCTION storage.search ( | ||
prefix TEXT, | ||
bucketname TEXT, | ||
limits INT DEFAULT 100, | ||
levels INT DEFAULT 1, | ||
offsets INT DEFAULT 0, | ||
search TEXT DEFAULT '', | ||
sortcolumn TEXT DEFAULT 'name', | ||
sortorder TEXT DEFAULT 'asc' | ||
) RETURNS TABLE ( | ||
name TEXT, | ||
id UUID, | ||
updated_at TIMESTAMPTZ, | ||
created_at TIMESTAMPTZ, | ||
last_accessed_at TIMESTAMPTZ, | ||
metadata JSONB | ||
) | ||
AS $$ | ||
DECLARE | ||
v_order_by TEXT; | ||
v_sort_order TEXT; | ||
BEGIN | ||
CASE | ||
WHEN sortcolumn = 'name' THEN | ||
v_order_by = 'name'; | ||
WHEN sortcolumn = 'updated_at' THEN | ||
v_order_by = 'updated_at'; | ||
WHEN sortcolumn = 'created_at' THEN | ||
v_order_by = 'created_at'; | ||
WHEN sortcolumn = 'last_accessed_at' THEN | ||
v_order_by = 'last_accessed_at'; | ||
ELSE | ||
v_order_by = 'name'; | ||
END CASE; | ||
|
||
CASE | ||
WHEN sortorder = 'asc' THEN | ||
v_sort_order = 'asc'; | ||
WHEN sortorder = 'desc' THEN | ||
v_sort_order = 'desc'; | ||
ELSE | ||
v_sort_order = 'asc'; | ||
END CASE; | ||
|
||
v_order_by = v_order_by || ' ' || v_sort_order; | ||
|
||
RETURN QUERY EXECUTE | ||
'WITH folders AS ( | ||
SELECT path_tokens[$1] AS folder | ||
FROM storage.objects | ||
WHERE STARTS_WITH(LOWER(objects.name), $2 || $3) | ||
AND bucket_id = $4 | ||
AND ARRAY_LENGTH(objects.path_tokens, 1) <> $1 | ||
GROUP BY folder | ||
ORDER BY folder ' || v_sort_order || ' | ||
) | ||
(SELECT folder AS "name", | ||
NULL AS id, | ||
NULL AS updated_at, | ||
NULL AS created_at, | ||
NULL AS last_accessed_at, | ||
NULL AS metadata FROM folders) | ||
UNION ALL | ||
(SELECT path_tokens[$1] AS "name", | ||
id, | ||
updated_at, | ||
created_at, | ||
last_accessed_at, | ||
metadata | ||
FROM storage.objects | ||
WHERE STARTS_WITH(LOWER(objects.name), $2 || $3) | ||
AND bucket_id = $4 | ||
AND ARRAY_LENGTH(objects.path_tokens, 1) = $1 | ||
ORDER BY ' || v_order_by || ') | ||
LIMIT $5 | ||
OFFSET $6' USING levels, LOWER(prefix), LOWER(search), bucketname, limits, offsets; | ||
END; | ||
$$ LANGUAGE plpgsql STABLE; | ||
|
||
CREATE OR REPLACE FUNCTION storage.list_objects_with_delimiter(bucket_id TEXT, prefix_param TEXT, delimiter_param TEXT, max_keys INTEGER DEFAULT 100, start_after TEXT DEFAULT '', next_token TEXT DEFAULT '') | ||
RETURNS TABLE (name TEXT, id UUID, metadata JSONB, updated_at TIMESTAMPTZ) AS | ||
$$ | ||
BEGIN | ||
RETURN QUERY EXECUTE | ||
'SELECT DISTINCT ON(name COLLATE "C") * FROM ( | ||
SELECT | ||
CASE | ||
WHEN POSITION($2 IN SUBSTRING(name FROM LENGTH($1) + 1)) > 0 THEN | ||
SUBSTRING(name FROM 1 for LENGTH($1) + POSITION($2 IN SUBSTRING(name FROM LENGTH($1) + 1))) | ||
ELSE | ||
name | ||
END AS name, id, metadata, updated_at | ||
FROM | ||
storage.objects | ||
WHERE | ||
bucket_id = $5 AND | ||
STARTS_WITH(LOWER(name), $1) AND | ||
CASE | ||
WHEN $6 != '''' THEN | ||
name COLLATE "C" > $6 | ||
ELSE true END | ||
AND CASE | ||
WHEN $4 != '''' THEN | ||
CASE | ||
WHEN POSITION($2 IN SUBSTRING(name FROM LENGTH($1) + 1)) > 0 THEN | ||
SUBSTRING(name FROM 1 FOR LENGTH($1) + POSITION($2 IN SUBSTRING(name FROM LENGTH($1) + 1))) COLLATE "C" > $4 | ||
ELSE | ||
name COLLATE "C" > $4 | ||
END | ||
ELSE | ||
TRUE | ||
END | ||
ORDER BY | ||
name COLLATE "C" ASC) AS e ORDER BY name COLLATE "C" LIMIT $3' | ||
USING LOWER(prefix_param), delimiter_param, max_keys, next_token, bucket_id, start_after; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE OR REPLACE FUNCTION storage.list_multipart_uploads_with_delimiter(bucket_id text, prefix_param text, delimiter_param text, max_keys integer default 100, next_key_token text DEFAULT '', next_upload_token text default '') | ||
RETURNS TABLE (key text, id text, created_at timestamptz) AS | ||
$$ | ||
BEGIN | ||
RETURN QUERY EXECUTE | ||
'SELECT DISTINCT ON(key COLLATE "C") * FROM ( | ||
SELECT | ||
CASE | ||
WHEN POSITION($2 IN SUBSTRING(key FROM LENGTH($1) + 1)) > 0 THEN | ||
SUBSTRING(key FROM 1 FOR LENGTH($1) + POSITION($2 IN SUBSTRING(key FROM LENGTH($1) + 1))) | ||
ELSE | ||
key | ||
END AS key, id, created_at | ||
FROM | ||
storage.s3_multipart_uploads | ||
WHERE | ||
bucket_id = $5 AND | ||
STARTS_WITH(LOWER(key), $1) AND | ||
CASE | ||
WHEN $4 != '''' AND $6 = '''' THEN | ||
CASE | ||
WHEN POSITION($2 IN SUBSTRING(key FROM LENGTH($1) + 1)) > 0 THEN | ||
SUBSTRING(key FROM 1 FOR LENGTH($1) + POSITION($2 IN SUBSTRING(key FROM LENGTH($1) + 1))) COLLATE "C" > $4 | ||
ELSE | ||
key COLLATE "C" > $4 | ||
END | ||
ELSE | ||
TRUE | ||
END AND | ||
CASE | ||
WHEN $6 != '''' THEN | ||
id COLLATE "C" > $6 | ||
ELSE | ||
TRUE | ||
END | ||
ORDER BY | ||
key COLLATE "C" ASC, created_at ASC) AS e ORDER BY key COLLATE "C" LIMIT $3' | ||
USING LOWER(prefix_param), delimiter_param, max_keys, next_key_token, bucket_id, next_upload_token; | ||
END; | ||
$$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.