From 9b0da64ce52f1006ad119670296278bcc8ec7657 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 8 Jan 2018 23:20:08 +0000 Subject: [PATCH] lib/postgres/mime.sql --- lib/postgres/mime.sql | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/postgres/mime.sql b/lib/postgres/mime.sql index 995cdb43..40e1cc4f 100644 --- a/lib/postgres/mime.sql +++ b/lib/postgres/mime.sql @@ -7,14 +7,22 @@ CREATE TABLE IF NOT EXISTS mime ( ); CREATE INDEX IF NOT EXISTS mime_ext_idx ON mime (ext); BEGIN TRANSACTION; -DELETE FROM mime; -COPY mime FROM PROGRAM 'true' WITH (format 'text', NULL ''); -COPY mime FROM PROGRAM 'curl -s https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types \ +CREATE TEMPORARY TABLE tmp_mime ON COMMIT DROP AS SELECT * FROM mime LIMIT 0; + +COPY mime FROM PROGRAM 'curl -s \ +https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types \ | tr -d "\n" \ | sed -E "s,^(.*?)]+>(.*?)(.*?)$,\2," \ | sed "s/<.tr>/\n/g" \ | grep ",\t,g" \ -| sed -E -e "s, *<[^>]+> *,,g" -e "s/^[\t ]*//" \ +| sed -E -e "s, *<[^>]+> *,,g" -e "s/^[\t ]*//" -e "s/([^\t]+)\t([^\t]+)$/\2\t\1/" \ ' WITH (format 'text', NULL ''); + +DELETE FROM tmp_mime; +COPY tmp_mime FROM PROGRAM 'curl -s https://gist.githubusercontent.com/electerious/3d5a31a73cfd6423f835c074ab25fc06/raw/d48b8410e9aa6746cfd946bca21a1bb54c351c4e/Caddyfile \ +| sed -e "s/^ *//" -e "/^[^\.]/d" -e "s/ /\t/" -e "s/$/\t/" \ +' WITH (format 'text', NULL ''); +INSERT INTO mime SELECT * FROM tmp_mime ON CONFLICT DO NOTHING; + COMMIT; -- 2.47.3