Permalink
Browse files

updated the code for new Upload module + other stuff

  • Loading branch information...
1 parent 608b125 commit 6350597c542ea38ab05b5cb252f17871e0634ac7 @Aqua-Ye committed Sep 11, 2011
Showing with 65 additions and 44 deletions.
  1. +15 −4 Makefile
  2. +1 −1 src/db.opa
  3. +40 −32 src/main.opa
  4. +9 −7 src/types.opa
View
@@ -1,7 +1,18 @@
-all: opa_share.exe
+S = @ # silent
-opa_share.exe: src/types.opa src/db.opa src/main.opa
- opa src/types.opa src/db.opa src/main.opa -o opa_share.exe
+.PHONY: all clean run $(EXE)
+
+OPA ?= opa
+MINIMAL_VERSION = 576
+EXE = opa_share.exe
+
+all: $(EXE)
+
+$(EXE): src/*.opa resources/*
+ $(OPA) --minimal-version $(MINIMAL_VERSION) src/types.opa src/db.opa src/main.opa -o $(EXE)
+
+run: all
+ $(S) ./$(EXE) || exit 0 ## prevent ugly make error 130 :) ##
clean:
- \rm -Rf *.exe _build _tracks *.log
+ rm -Rf *.exe _build _tracks *.log **/#*#
View
@@ -1 +1 @@
-db /files : intmap(file)
+db /files : intmap(OpaShare.file)
View
@@ -18,46 +18,54 @@
import stdlib.{upload}
-on_upload(data, res) =
- file =
- match data
- ~{content filename fold_headers=_ name=_} ->
- match content()
- ~{content} -> some({
- name = filename
- size = String.length(content)
- content = content
- date_uploaded = Date.now()
- date_downloaded = Date.now()
- password = none
- })
- _ -> {none}
- end
- _ -> {none}
- //do jlog("{file}")
- //do init_upload()
- do match file
- ~{some} ->
- key = Db.fresh_key(@/files)
- do jlog("Uploaded @{key}")
- /files[key] <- some
- _ -> void
- _ = init_upload() // @error Reentrant routine
- res
+OpaShare = {{
-upload_config() = { Upload.default_config(void) with
- fold_datas = on_upload
-} : Upload.config(void)
+ rec val upload_config = {
+ Upload.default_config() with
+ form_id = "share"
+ process = process_upload
+ } : Upload.config
-init_upload() =
- Dom.transform([#upload <- Upload.make(upload_config())])
+ upload_done(key) =
+ do Dom.clear_value(Dom.select_raw("#upload_form > input[name=filename]"))
+ do Dom.transform([
+ #msg <- "Download your file @ http://localhost:8080/files/{key}",
+ #upload <- Upload.html(OpaShare.upload_config)
+ ])
+ void
+
+ process_upload(data) =
+ files = data.uploaded_files
+ StringMap.iter(
+ _, file ->
+ os_file = {
+ name = file.filename
+ size = String.length(file.content)
+ content = file.content
+ mimetype = file.mimetype
+ date_uploaded = Date.now()
+ date_downloaded = Date.now()
+ count = 0
+ password = none
+ } : OpaShare.file
+ key = Db.fresh_key(@/files)
+ do jlog("Uploaded @{key}")
+ do /files[key] <- os_file
+ upload_done(key)
+ , files)
+
+ upload_html() =
+ Upload.html(OpaShare.upload_config)
+
+}}
main() =
<div id=#header>
<h1>Welcome to OpaShare</h1>
</div>
<div id=#content>
- <div id=#upload onready={_->init_upload()}/>
+ <div id=#upload>{OpaShare.upload_html()}</div>
+ <div id=#msg></div>
</div>
server = Server.one_page_bundle("OpaShare",
View
@@ -1,8 +1,10 @@
-type file = {
- name: string
- size: int
- content: binary
- date_uploaded: Date.date
- date_downloaded: Date.date
- password: option(string)
+type OpaShare.file = {
+ name: string // file name
+ size: int // file size
+ content: binary // file content
+ mimetype: string // file mimetype
+ date_uploaded: Date.date // upload date
+ date_downloaded: Date.date // last download date
+ count: int // download counter
+ password: option(string) // file password
}

0 comments on commit 6350597

Please sign in to comment.