Changeset

2646:45ef16ebe565

mod_http_upload: Generate shorter directory names (closes #822)
author Kim Alvefur <zash@zash.se>
date Fri, 24 Mar 2017 01:07:54 +0100
parents 2645:cae371544ff5
children 2647:d8487d5bd4fb
files mod_http_upload/mod_http_upload.lua
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_upload/mod_http_upload.lua	Thu Mar 23 14:36:20 2017 +0100
+++ b/mod_http_upload/mod_http_upload.lua	Fri Mar 24 01:07:54 2017 +0100
@@ -10,15 +10,23 @@
 -- imports
 local st = require"util.stanza";
 local lfs = require"lfs";
-local uuid = require"util.uuid".generate;
 local url = require "socket.url";
 local dataform = require "util.dataforms".new;
 local datamanager = require "util.datamanager";
 local t_concat = table.concat;
 local t_insert = table.insert;
 local s_upper = string.upper;
+local have_random, random = pcall(require, "util.random"); -- Only available in 0.10+
+local uuid = require"util.uuid".generate;
+if have_random then
+	local b64 = require "util.encodings".base64;
+	local b64url = { ['+'] = '-', ['/'] = '_', ['='] = '' };
+	function uuid()
+		return (b64(random(8)):gsub("[+/=]", b64url));
+	end
+end
 
-local function join_path(...)
+local function join_path(...) -- COMPAT util.path was added in 0.10
 	return table.concat({ ... }, package.config:sub(1,1));
 end