]> git.nbdom.net Git - nb.git/commitdiff
lib/postgres/mime.sql
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 8 Jan 2018 22:14:37 +0000 (22:14 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 8 Jan 2018 22:14:37 +0000 (22:14 +0000)
lib/postgres/mime.sql [new file with mode: 0644]

diff --git a/lib/postgres/mime.sql b/lib/postgres/mime.sql
new file mode 100644 (file)
index 0000000..995cdb4
--- /dev/null
@@ -0,0 +1,20 @@
+DROP TABLE IF EXISTS mime;
+CREATE TABLE IF NOT EXISTS mime (
+       ext varchar(128),
+       type varchar(128) NOT NULL DEFAULT '',
+       name varchar(128),
+       PRIMARY KEY(type,ext)
+);
+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 \
+| tr -d "\n" \
+| sed -E "s,^(.*?)<table[^>]+>(.*?)</table>(.*?)$,\2," \
+| sed "s/<.tr>/\n/g" \
+| grep "<td" \
+| sed "s,<td>,\t,g" \
+| sed -E -e "s, *<[^>]+> *,,g" -e "s/^[\t ]*//" \
+' WITH (format 'text', NULL '');
+COMMIT;