struggle 1.4.3 → 1.4.5
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/struggle/{fileupload.rb → tfile.rb} +47 -16
- data/lib/struggle.rb +1 -1
- data/struggle.gemspec +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 956bbcdc489c15f0599b1a6a4702b79724850b4e
|
4
|
+
data.tar.gz: 302ccf32d2892df12c185e801c3a5d76faf96323
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d82cc833c79ca70a4451f966ee8dbff370b3133d81ff4f11632e849c227c69e7069bcec5d2b764a23163bf43c7e1b076581be0543c10b7cb33cc27b9a060622
|
7
|
+
data.tar.gz: fbed4c8b69d9d1a19608f7aaf62083e03dae766f29793d0e50a90182cad6433f7e13ae86372a93e7e43068f1e70aa0ad72d7b802e9fc660da941b0f1a75897c3
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Struggle
|
2
|
-
class
|
2
|
+
class Tfile
|
3
3
|
#file upload
|
4
4
|
#params: file->file stream,filepath->file save path,rule->can upload file format("jpg|xls"),minsize and maxsize->minsize<file's size<maxsize
|
5
5
|
#return: {state: true, result: "new filename"} or {state: false, result: "error message"}
|
6
|
-
def
|
7
|
-
result =
|
6
|
+
def Tfile.upload(file, filepath="", rule="jpg|xls", minsize=1, maxsize=4000)
|
7
|
+
result = Tfile.rule_validata(file, rule, minsize, maxsize)
|
8
8
|
if result[:state]
|
9
|
-
sname =
|
9
|
+
sname = Tfile.getname(file, filepath)
|
10
10
|
begin
|
11
11
|
unless Dir::exist?(filepath)
|
12
12
|
unless system("mkdir -p #{filepath}")
|
@@ -25,11 +25,42 @@ module Struggle
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
#before unpack init
|
29
|
+
def Tfile.unpack_init
|
30
|
+
soft = ""
|
31
|
+
if system("unzip").nil?
|
32
|
+
soft += "unzip "
|
33
|
+
elsif system("unrar").nil?
|
34
|
+
soft += "unrar "
|
35
|
+
elsif system("tar").nil?
|
36
|
+
soft += "tar "
|
37
|
+
end
|
38
|
+
unless soft.blank?
|
39
|
+
system("sudo apt-get install #{soft}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
#file unpack
|
43
|
+
#file->file path
|
44
|
+
#path->unpacked path
|
45
|
+
#return->true, false, nil. nil not cmd
|
46
|
+
def Tfile.unpack(file, path)
|
47
|
+
format = Tfile.file_format(file)
|
48
|
+
cmd = ""
|
49
|
+
if format==".gz" || format==".bz2" || format==".tar"
|
50
|
+
cmd="tar -zxvf #{file} -C #{path}"
|
51
|
+
elsif format==".zip"
|
52
|
+
cmd="unzip #{file} -d #{path}"
|
53
|
+
elsif format==".rar"
|
54
|
+
cmd="unrar e #{file} #{path}"
|
55
|
+
end
|
56
|
+
system cmd
|
57
|
+
end
|
58
|
+
|
28
59
|
#validate file
|
29
60
|
#params:file->file stream,rule->can upload file format,minsize<file's size<maxsize
|
30
61
|
#return:{state: true} or return {state: false, message: "error message"}
|
31
|
-
def
|
32
|
-
rule_for =
|
62
|
+
def Tfile.rule_validata(file, rule, minsize, maxsize)
|
63
|
+
rule_for = Tfile.filename_validata(file, rule)
|
33
64
|
unless rule_for
|
34
65
|
return {state: false, message: "错误:文件格式不对,只允许上传#{rule}格式!\\n"}
|
35
66
|
end
|
@@ -42,15 +73,15 @@ module Struggle
|
|
42
73
|
#validate file format
|
43
74
|
#params: file-> file stream; rule-> validate rule ("jpg|xls")
|
44
75
|
#return: validate result -> true | false
|
45
|
-
def
|
76
|
+
def Tfile.filename_validata(file, rule)
|
46
77
|
!eval("/\.(#{rule})+$/").match(file.original_filename).blank?
|
47
78
|
end
|
48
79
|
|
49
80
|
#get new file's name
|
50
81
|
#params:filestream->file stream file name,filepath->file save path
|
51
82
|
#return:new file's name
|
52
|
-
def
|
53
|
-
file_for =
|
83
|
+
def Tfile.getname(filestream, filepath)
|
84
|
+
file_for = Tfile.file_format(filestream.original_filename)
|
54
85
|
filename = Time.now.strftime("%Y%m%d%h%m%s")<<rand(99999).to_s<<file_for
|
55
86
|
file = filepath+filename
|
56
87
|
while File.exist?(file) do
|
@@ -63,17 +94,17 @@ module Struggle
|
|
63
94
|
#get file format
|
64
95
|
#params: filename->file's name
|
65
96
|
#return: file format '.jpg','.exe'
|
66
|
-
def
|
97
|
+
def Tfile.file_format(filename)
|
67
98
|
/\.[^\.]+$/.match(filename)[0]
|
68
99
|
end
|
69
100
|
|
70
101
|
#image upload
|
71
102
|
#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
|
72
103
|
#return: {state: true, result: "new filename"} or {state: false, result: "error message"}
|
73
|
-
def
|
74
|
-
result =
|
104
|
+
def Tfile.imageupload(imgfile, filepath="", rule="jpg|jpeg", minsize=0, maxsize=2000, w=0, h=0)
|
105
|
+
result = Tfile.rule_validata(imgfile, rule, minsize, maxsize)
|
75
106
|
if result[:state]
|
76
|
-
sname =
|
107
|
+
sname = Tfile.getname(imgfile, filepath)
|
77
108
|
begin
|
78
109
|
unless Dir::exist?(filepath)
|
79
110
|
unless system("mkdir -p #{filepath}")
|
@@ -83,7 +114,7 @@ module Struggle
|
|
83
114
|
File.open(filepath+sname, "wb") do |f|
|
84
115
|
f.write(imgfile.read)
|
85
116
|
end
|
86
|
-
|
117
|
+
Tfile.resize(filepath + sname, w, h)
|
87
118
|
return {state: true, result: sname}
|
88
119
|
rescue
|
89
120
|
return {state: false, result: "写入图片失败:#{$!}"}
|
@@ -96,13 +127,13 @@ module Struggle
|
|
96
127
|
#delete dir
|
97
128
|
#params: dir-> dir path
|
98
129
|
#return true or false
|
99
|
-
def
|
130
|
+
def Tfile.rmdir(dir)
|
100
131
|
system("rm -rf #{dir}")
|
101
132
|
end
|
102
133
|
|
103
134
|
#image resize
|
104
135
|
#params: imagepath-> image file path; w-> new image width; h-> new image height
|
105
|
-
def
|
136
|
+
def Tfile.resize(imagepath, w, h)
|
106
137
|
img = Magick::Image.read(imagepath)[0]
|
107
138
|
if w==0 || h==0
|
108
139
|
w=img.columns
|
data/lib/struggle.rb
CHANGED
data/struggle.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'struggle'
|
3
|
-
s.version = '1.4.
|
4
|
-
s.date = '2015-07-
|
3
|
+
s.version = '1.4.5'
|
4
|
+
s.date = '2015-07-31'
|
5
5
|
s.summary = "struggle!"
|
6
|
-
s.description = "vcode,
|
6
|
+
s.description = "vcode,tfile,pager,func,logistic,pay_gateway,tmagick,html_extend;"
|
7
7
|
s.authors = ["lean"]
|
8
8
|
s.email = '54850915@qq.com'
|
9
9
|
s.files = `git ls-files`.split("\n")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: struggle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lean
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iconv
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: vcode,
|
41
|
+
description: vcode,tfile,pager,func,logistic,pay_gateway,tmagick,html_extend;
|
42
42
|
email: 54850915@qq.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
@@ -47,13 +47,13 @@ extra_rdoc_files:
|
|
47
47
|
files:
|
48
48
|
- README.md
|
49
49
|
- lib/struggle.rb
|
50
|
-
- lib/struggle/fileupload.rb
|
51
50
|
- lib/struggle/func.rb
|
52
51
|
- lib/struggle/html_extend.rb
|
53
52
|
- lib/struggle/logistic.rb
|
54
53
|
- lib/struggle/pager.rb
|
55
54
|
- lib/struggle/pay_gateway.rb
|
56
55
|
- lib/struggle/sms.rb
|
56
|
+
- lib/struggle/tfile.rb
|
57
57
|
- lib/struggle/tmagick.rb
|
58
58
|
- lib/struggle/vcode.rb
|
59
59
|
- struggle.gemspec
|