attempt to create a specific file system handler for the upload, i.e. extend it. there is an error i cannot solve
This commit is contained in:
@@ -11,7 +11,8 @@ inherit
|
||||
redefine
|
||||
install,
|
||||
initialize,
|
||||
setup_hooks
|
||||
setup_hooks,
|
||||
permissions
|
||||
end
|
||||
|
||||
CMS_HOOK_BLOCK
|
||||
@@ -37,6 +38,23 @@ feature -- Access
|
||||
|
||||
name: STRING
|
||||
|
||||
permissions: LIST [READABLE_STRING_8]
|
||||
-- List of permission ids, used by this module, and declared.
|
||||
do
|
||||
Result := Precursor
|
||||
Result.force ("manage admin")
|
||||
Result.force ("admin users")
|
||||
Result.force ("admin roles")
|
||||
Result.force ("admin modules")
|
||||
Result.force ("install modules")
|
||||
Result.force ("admin core caches")
|
||||
Result.force ("clear blocks cache")
|
||||
Result.force ("admin export")
|
||||
Result.force ("export core")
|
||||
|
||||
Result.force ("upload files")
|
||||
end
|
||||
|
||||
feature {CMS_API} -- Module Initialization
|
||||
|
||||
initialize (api: CMS_API)
|
||||
@@ -119,8 +137,11 @@ feature -- Hooks
|
||||
link: CMS_LOCAL_LINK
|
||||
second_link: CMS_LOCAL_LINK
|
||||
do
|
||||
create link.make ("Upload", "upload/")
|
||||
a_menu_system.primary_menu.extend (link)
|
||||
-- login in demo did somehow not work
|
||||
-- if a_response.has_permission ("upload files") then
|
||||
create link.make ("Upload", "upload/")
|
||||
a_menu_system.primary_menu.extend (link)
|
||||
-- end
|
||||
end
|
||||
|
||||
feature -- Configuration
|
||||
@@ -177,7 +198,8 @@ feature -- Handler
|
||||
file_name: STRING_8
|
||||
stored: BOOLEAN
|
||||
file_system_handler: WSF_FILE_SYSTEM_HANDLER
|
||||
|
||||
file_system_upload_handler: CMS_FILE_UPLOAD_FILE_SYSTEM_HANDLER
|
||||
uploaded_file: CMS_FILE_UPLOAD_FILE
|
||||
do
|
||||
-- if has uploaded files, then store them
|
||||
if req.has_uploaded_file then
|
||||
@@ -202,7 +224,7 @@ feature -- Handler
|
||||
file_system_handler.process_index ("/uploaded_files", files_root, req, res)
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature -- Mapping helper: uri template agent (analogue to the demo-module)
|
||||
|
||||
|
||||
61
modules/file_upload/cms_file_upload_file.e
Normal file
61
modules/file_upload/cms_file_upload_file.e
Normal file
@@ -0,0 +1,61 @@
|
||||
note
|
||||
description: "Summary description for {CMS_FILE_UPLOAD_FILE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_FILE_UPLOAD_FILE
|
||||
|
||||
inherit
|
||||
WSF_UPLOADED_FILE
|
||||
redefine
|
||||
name
|
||||
end
|
||||
|
||||
RAW_FILE
|
||||
undefine
|
||||
make, change_name, is_empty, exists
|
||||
end
|
||||
|
||||
create
|
||||
make_new,
|
||||
make_with_path
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make_new (a_name: READABLE_STRING_GENERAL; a_filename: READABLE_STRING_GENERAL; a_content_type: like content_type; a_size: like size; a_user: CMS_USER)
|
||||
local
|
||||
time: DATE_TIME
|
||||
do
|
||||
new_name := a_name.as_string_32
|
||||
url_encoded_name := url_encoded_string (a_name)
|
||||
filename := a_filename.as_string_32
|
||||
content_type := a_content_type
|
||||
size := a_size
|
||||
|
||||
create time.make_now_utc
|
||||
set_uploaded_time (time)
|
||||
set_uploaded_by (a_user)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
uploaded_by: CMS_USER
|
||||
-- user who has uploaded the file
|
||||
|
||||
uploaded_time: DATE_TIME
|
||||
-- time and date when file was uploaded
|
||||
|
||||
feature -- Setter functions
|
||||
|
||||
set_uploaded_by (a_user: CMS_USER)
|
||||
do
|
||||
uploaded_by := a_user
|
||||
end
|
||||
|
||||
set_uploaded_time (a_time: DATE_TIME)
|
||||
do
|
||||
uploaded_time := a_time
|
||||
end
|
||||
end
|
||||
145
modules/file_upload/cms_file_upload_file_system_handler.e
Normal file
145
modules/file_upload/cms_file_upload_file_system_handler.e
Normal file
@@ -0,0 +1,145 @@
|
||||
note
|
||||
description: "Summary description for {CMS_FILE_UPLOAD_FILE_SYSTEM_HANDLER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_FILE_UPLOAD_FILE_SYSTEM_HANDLER
|
||||
|
||||
inherit
|
||||
WSF_FILE_SYSTEM_HANDLER
|
||||
redefine
|
||||
process_index
|
||||
end
|
||||
|
||||
create
|
||||
make_with_p
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make_with_p (d: like document_root)
|
||||
do
|
||||
if d.is_empty then
|
||||
document_root := execution_environment.current_working_path
|
||||
else
|
||||
document_root := d
|
||||
end
|
||||
ensure
|
||||
not document_root.is_empty
|
||||
end
|
||||
|
||||
feature -- process function
|
||||
|
||||
process_index (a_uri: READABLE_STRING_8; dn: PATH; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
h: HTTP_HEADER
|
||||
uri, s: STRING_8
|
||||
d: DIRECTORY
|
||||
l_files: LIST [PATH]
|
||||
p: PATH
|
||||
n: READABLE_STRING_32
|
||||
httpdate: HTTP_DATE
|
||||
pf: RAW_FILE
|
||||
l_is_dir: BOOLEAN
|
||||
do
|
||||
create d.make_with_path (dn)
|
||||
d.open_read
|
||||
if attached directory_index_file (d) as f then
|
||||
process_file (f, req, res)
|
||||
else
|
||||
uri := a_uri
|
||||
if not uri.is_empty and then uri [uri.count] /= '/' then
|
||||
uri.append_character ('/')
|
||||
end
|
||||
s := "[
|
||||
<html>
|
||||
<head>
|
||||
<title>Index of $URI</title>
|
||||
<style>
|
||||
td { padding-left: 10px;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Index of $URI</h1>
|
||||
<table>
|
||||
<tr><th/><th>Name</th><th>Last modified</th><th>Size</th></tr>
|
||||
<tr><th colspan="4"><hr></th></tr>
|
||||
]"
|
||||
s.replace_substring_all ("$URI", uri)
|
||||
|
||||
from
|
||||
l_files := d.entries
|
||||
l_files.start
|
||||
until
|
||||
l_files.after
|
||||
loop
|
||||
p := l_files.item
|
||||
if ignoring_index_entry (p) then
|
||||
|
||||
else
|
||||
n := p.name
|
||||
create pf.make_with_path (dn.extended_path (p))
|
||||
if pf.exists and then pf.is_directory then
|
||||
l_is_dir := True
|
||||
else
|
||||
l_is_dir := False
|
||||
end
|
||||
|
||||
s.append ("<tr><td>")
|
||||
if l_is_dir then
|
||||
s.append ("[dir]")
|
||||
else
|
||||
s.append (" ")
|
||||
end
|
||||
s.append ("</td>")
|
||||
s.append ("<td><a href=%"" + uri)
|
||||
url_encoder.append_percent_encoded_string_to (n, s)
|
||||
s.append ("%">")
|
||||
if p.is_parent_symbol then
|
||||
s.append ("[Parent Directory] ..")
|
||||
else
|
||||
s.append (html_encoder.encoded_string (n))
|
||||
end
|
||||
if l_is_dir then
|
||||
s.append ("/")
|
||||
end
|
||||
|
||||
s.append ("</td>")
|
||||
s.append ("<td>")
|
||||
if pf.exists then
|
||||
create httpdate.make_from_date_time (file_date (pf))
|
||||
httpdate.append_to_rfc1123_string (s)
|
||||
end
|
||||
s.append ("</td>")
|
||||
s.append ("<td>")
|
||||
if not l_is_dir and pf.exists then
|
||||
s.append_integer (file_size (pf))
|
||||
end
|
||||
s.append ("</td>")
|
||||
s.append ("</tr>")
|
||||
end
|
||||
l_files.forth
|
||||
end
|
||||
s.append ("[
|
||||
<tr><th colspan="4"><hr></th></tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
)
|
||||
|
||||
create h.make
|
||||
h.put_content_type_text_html
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||
h.put_content_length (s.count)
|
||||
res.put_header_lines (h)
|
||||
if not req.request_method.same_string ({HTTP_REQUEST_METHODS}.method_head) then
|
||||
res.put_string (s)
|
||||
end
|
||||
res.flush
|
||||
end
|
||||
d.close
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user