leangem 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fileupload.rb +82 -35
- data/lib/pay_gateway.rb +1 -10
- data/lib/vcode.rb +1 -1
- metadata +4 -5
- data/lib/imageupload.rb +0 -107
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 888190a3bf33554cc5c8a68ad0cd1258f9480ad2
|
4
|
+
data.tar.gz: f797196b103cc32d7f60c52aa7323a7c38f7aa7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3403d4bcb39fcb50652ff090f942fcf31e305d99504467c824ad2199d0f3bf7e05846018c53de37c34e4ce9265ea994b8efa52e188dba8e7c37ba5c52d6a4bed
|
7
|
+
data.tar.gz: ba659fdca50238e1753acf8c4396ae806b4038c61c09adbafe3eca9afd81db76f5f88f8597f18f24f8365c5c9a4c6a1c80a2b47f19bf64100cc916186fdbeba9
|
data/lib/fileupload.rb
CHANGED
@@ -1,49 +1,96 @@
|
|
1
1
|
class Fileupload
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
#file upload
|
3
|
+
#params: file->file stream,filepath->file save path,rule->can upload file format("jpg|xls"),minsize and maxsize->minsize<file's size<maxsize
|
4
|
+
#return: {state: true, result: "new filename"} or {state: false, result: "error message"}
|
5
|
+
def Fileupload.upload(file, filepath="", rule="jpg|xls", minsize=1, maxsize=4000)
|
6
|
+
result = Fileupload.rule_validata(file, rule, minsize, maxsize)
|
7
|
+
if result[:state]
|
8
|
+
sname = Fileupload.getname(file.original_filename, filepath)
|
9
|
+
begin
|
10
|
+
unless Dir::exist?(filepath)
|
11
|
+
Dir.mkdir(filepath)
|
12
|
+
end
|
13
|
+
File.open(filepath+sname, "wb") do |f|
|
14
|
+
f.write(file.read)
|
15
|
+
end
|
16
|
+
rescue
|
17
|
+
return {state: false, result: "写入文件失败:#{$!}"}
|
14
18
|
end
|
15
|
-
sname
|
19
|
+
return {state: true, result: sname}
|
20
|
+
else
|
21
|
+
return {state: false, result: result[:message]}
|
16
22
|
end
|
17
23
|
end
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
#validate file
|
26
|
+
#params:file->file stream,rule->can upload file format,minsize<file's size<maxsize
|
27
|
+
#return:{state: true} or return {state: false, message: "error message"}
|
28
|
+
def Fileupload.rule_validata(file, rule, minsize, maxsize)
|
29
|
+
rule_for = eval("/\.(#{rule})+$/").match(file.original_filename)
|
30
|
+
if rule_for.nil? || rule_for.blank?
|
31
|
+
return {state: false, message: "错误:文件格式不对,只允许上传#{rule}格式!\\n"}
|
25
32
|
end
|
26
|
-
if file.size
|
27
|
-
|
28
|
-
return false
|
33
|
+
if file.size<minsize*1024 || file.size>maxsize*1024
|
34
|
+
return {state: false, message: "错误:文件大小错误,只允许#{minsize}kb~#{maxsize}kb!\\n"}
|
29
35
|
end
|
30
|
-
return true
|
31
|
-
end
|
32
|
-
|
33
|
-
#错误提示
|
34
|
-
def message
|
35
|
-
@message
|
36
|
+
return {state: true}
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
#get new file's name
|
40
|
+
#params:filestream->file stream file name,filepath->file save path
|
41
|
+
#return:new file's name
|
42
|
+
def Fileupload.getname(filestream, filepath)
|
43
|
+
file_for = Fileupload.file_format(filestream)
|
44
|
+
filename = Time.now.strftime("%Y%m%d%h%m%s")<<rand(99999).to_s<<file_for
|
45
|
+
file = filepath+filename
|
43
46
|
while File.exist?(file) do
|
44
|
-
filename = Time.now.strftime("%Y%m%d%h%m%s")<<rand(99999).to_s<<
|
45
|
-
file =
|
47
|
+
filename = Time.now.strftime("%Y%m%d%h%m%s")<<rand(99999).to_s<<file_for
|
48
|
+
file = filepath+filename
|
46
49
|
end
|
47
50
|
filename
|
48
51
|
end
|
52
|
+
|
53
|
+
#get file format
|
54
|
+
#params: filename->file's name
|
55
|
+
#return: file format '.jpg','.exe'
|
56
|
+
def Fileupload.file_format(filename)
|
57
|
+
/\.[^\.]+$/.match(filename)[0]
|
58
|
+
end
|
59
|
+
|
60
|
+
#image upload
|
61
|
+
#params: file->file stream; filepath->file save path; rule->can upload file format("jpg|xls"); minsize and maxsize->minsize<file's size<maxsize; w->new image width, h->new image height
|
62
|
+
#return: {state: true, result: "new filename"} or {state: false, result: "error message"}
|
63
|
+
def Fileupload.imageupload(imgfile, filepath="", rule="jpg|jpeg", minsize=0, maxsize=2000, w=0, h=0)
|
64
|
+
result = Fileupload.rule_validata(imgfile, rule, minsize, maxsize)
|
65
|
+
if result[:state]
|
66
|
+
sname = Fileupload.getname(imgfile.original_filename, filepath)
|
67
|
+
begin
|
68
|
+
unless Dir::exist?(filepath)
|
69
|
+
Dir.mkdir(filepath)
|
70
|
+
end
|
71
|
+
File.open(filepath+sname, "wb") do |f|
|
72
|
+
f.write(imgfile.read)
|
73
|
+
end
|
74
|
+
rescue
|
75
|
+
return {state: false, result: "写入图片失败:#{$!}"}
|
76
|
+
end
|
77
|
+
Fileupload.resize(filepath + sname, w, h)
|
78
|
+
return {state: true, result: sname}
|
79
|
+
else
|
80
|
+
return {state: false, result: result[:message]}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
#image resize
|
85
|
+
#params: imagepath-> image file path; w-> new image width; h-> new image height
|
86
|
+
def Fileupload.resize(imagepath, w, h)
|
87
|
+
img = Magick::Image.read(imagepath)[0]
|
88
|
+
if w==0 || h==0
|
89
|
+
w=img.columns
|
90
|
+
h=img.rows
|
91
|
+
end
|
92
|
+
newimg = img.resize_to_fill(w, h)
|
93
|
+
newimg.write(imagepath)
|
94
|
+
end
|
95
|
+
|
49
96
|
end
|
data/lib/pay_gateway.rb
CHANGED
@@ -11,7 +11,7 @@ class PayGateway
|
|
11
11
|
# v_mid:商户编号
|
12
12
|
# key:商户md5密钥
|
13
13
|
# v_url:支付成功后跳转的页面
|
14
|
-
# remark2
|
14
|
+
# remark2:异步订单状态地址
|
15
15
|
# v_oid:订单编号
|
16
16
|
# v_amount:订单金额
|
17
17
|
# v_moneytype:支付货币类型
|
@@ -28,15 +28,6 @@ class PayGateway
|
|
28
28
|
# 功能:自动验证结果
|
29
29
|
# 参数:
|
30
30
|
# params参数
|
31
|
-
# v_oid = Request["v_oid"];
|
32
|
-
# v_pstatus = Request["v_pstatus"];
|
33
|
-
# v_pstring = Request["v_pstring"];
|
34
|
-
# v_pmode = Request["v_pmode"];
|
35
|
-
# v_md5str = Request["v_md5str"];
|
36
|
-
# v_amount = Request["v_amount"];
|
37
|
-
# v_moneytype = Request["v_moneytype"];
|
38
|
-
# remark1 = Request["remark1"];
|
39
|
-
# remark2 = Request["remark2"];
|
40
31
|
# key商户的md5密钥
|
41
32
|
# 返回:如果支付成功返回订单号,否则返回nil
|
42
33
|
def self.receive(params,key)
|
data/lib/vcode.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leangem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lean
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2010-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: vcode,fileupload,pager,
|
13
|
+
description: vcode,fileupload,pager,func,pay_gateway
|
14
14
|
email: leanv@sina.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -18,7 +18,6 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- lib/fileupload.rb
|
20
20
|
- lib/func.rb
|
21
|
-
- lib/imageupload.rb
|
22
21
|
- lib/pager.rb
|
23
22
|
- lib/pay_gateway.rb
|
24
23
|
- lib/vcode.rb
|
@@ -42,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
41
|
version: '0'
|
43
42
|
requirements: []
|
44
43
|
rubyforge_project:
|
45
|
-
rubygems_version: 2.
|
44
|
+
rubygems_version: 2.2.2
|
46
45
|
signing_key:
|
47
46
|
specification_version: 4
|
48
47
|
summary: leangem!
|
data/lib/imageupload.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
class Imageupload
|
2
|
-
#初始化
|
3
|
-
#临时路径
|
4
|
-
#图片路径
|
5
|
-
#清理垃圾,=0不清理
|
6
|
-
def initialize(minsize=10, maxsize=400, snappath="app/assets/images/snap/", imagepath="app/assets/images/upload/", cleartime=10, bigpath="app/assets/images/upload/")
|
7
|
-
@minsize = minsize*1024
|
8
|
-
@maxsize = maxsize*1024
|
9
|
-
@snappath = snappath
|
10
|
-
@imagepath = imagepath
|
11
|
-
@cleartime = cleartime
|
12
|
-
@bigpath = bigpath
|
13
|
-
@message=""
|
14
|
-
end
|
15
|
-
|
16
|
-
#忽略高宽就是自定义大小,传原图到临时空间
|
17
|
-
def upload(imgfile, rw=0, rh=0, dw=0, dh=0)
|
18
|
-
if self.img_validata(imgfile)
|
19
|
-
sname = self.getname(imgfile.original_filename)
|
20
|
-
imgpath = rw==0 || rh==0 ? @snappath+sname : @imagepath+sname
|
21
|
-
File.open(imgpath, "wb") do |f|
|
22
|
-
f.write(imgfile.read)
|
23
|
-
end
|
24
|
-
if @cleartime>0
|
25
|
-
self.clearsnap(sname)
|
26
|
-
end
|
27
|
-
if rw==0 || rh==0
|
28
|
-
return sname
|
29
|
-
else
|
30
|
-
self.resize(rw, rh, sname, dw, dh)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
#自定义剪裁缩放
|
36
|
-
def reimage(x, y, w, h, rw, rh, pname)
|
37
|
-
imgsnap = @snappath+pname
|
38
|
-
imgp = @imagepath+pname
|
39
|
-
img = Magick::Image.read(imgsnap)[0]
|
40
|
-
if w==0 || h==0
|
41
|
-
rc = img.resize(rw, rh)
|
42
|
-
rc.write(imgp)
|
43
|
-
else
|
44
|
-
chopped = img.crop(x, y, w, h)
|
45
|
-
rc = chopped.resize(rw, rh)
|
46
|
-
rc.write(imgp)
|
47
|
-
end
|
48
|
-
File.delete(imgsnap)
|
49
|
-
end
|
50
|
-
|
51
|
-
#错误提示
|
52
|
-
def message
|
53
|
-
@message
|
54
|
-
end
|
55
|
-
|
56
|
-
#固定剪裁缩放
|
57
|
-
def resize(rw, rh, imgname, dw, dh)
|
58
|
-
img = Magick::Image.read(@imagepath+imgname)[0]
|
59
|
-
newimg = img.resize_to_fill(rw, rh)
|
60
|
-
newimg.write(@imagepath+imgname)
|
61
|
-
if dw!=0 && dh !=0
|
62
|
-
name= imgname[0, imgname.length-4]
|
63
|
-
format= imgname[imgname.length-4, 4]
|
64
|
-
bigimg=img.resize_to_fill(dw, dh)
|
65
|
-
bigimg.write(@bigpath+name+"b"+format)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
#大小限制,类型限制,都放进模型层中。
|
70
|
-
def img_validata(img_file)
|
71
|
-
|
72
|
-
img_for = /\.(jpg|gif|GIF|png|jpeg|bmp|BMP|JPG|JPEG|PNG)+$/.match(img_file.original_filename)
|
73
|
-
if img_for.nil? || img_for.blank?
|
74
|
-
@message="错误:图片格式不对,只允许上传jpg,gif,png,bmp,jpeg格式!\\n"
|
75
|
-
return false
|
76
|
-
end
|
77
|
-
if img_file.size<@minsize || img_file.size>@maxsize
|
78
|
-
@message="错误:图片大小错误,只允许#{@minsize}kb~#{@maxsize}kb!\\n"
|
79
|
-
return false
|
80
|
-
end
|
81
|
-
return true
|
82
|
-
end
|
83
|
-
|
84
|
-
#保证名称不重复
|
85
|
-
def getname(img_file)
|
86
|
-
img_for = img_file[img_file.length-4, 4]
|
87
|
-
filename = Time.now.strftime("%Y%m%d%h%m%s")<<rand(99999).to_s<<img_for
|
88
|
-
file = @imagepath+filename
|
89
|
-
while File.exist?(file) do
|
90
|
-
filename = Time.now.strftime("%Y%m%d%h%m%s")<<rand(99999).to_s<<img_for
|
91
|
-
file = @imagepath+filename
|
92
|
-
end
|
93
|
-
filename
|
94
|
-
end
|
95
|
-
|
96
|
-
#删除原图
|
97
|
-
def clearsnap(snapname)
|
98
|
-
Thread.new do
|
99
|
-
snapimg = @snappath+snapname
|
100
|
-
sleep @cleartime
|
101
|
-
if File.exist?(snapimg)
|
102
|
-
File.delete(snapimg)
|
103
|
-
end
|
104
|
-
Thread.current.kill
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|