Class: Fcfinder::Connector
- Inherits:
-
Object
- Object
- Fcfinder::Connector
- Defined in:
- lib/fcfinder/connector.rb
Instance Attribute Summary collapse
-
#run ⇒ Object
readonly
Returns the value of attribute run.
Instance Method Summary collapse
- #add_zip_file(path, output_file) ⇒ Object
- #all_file_list(url) ⇒ Object
- #append_file(files_url) ⇒ Object
- #copy(file, target) ⇒ Object
- #copy!(file, target) ⇒ Object
- #create_directory(path, directory_name) ⇒ Object
- #cut(file, target) ⇒ Object
- #cut!(file, target) ⇒ Object
- #delete!(path) ⇒ Object
- #directory_size(path) ⇒ Object
- #download(path) ⇒ Object
- #duplicate(file) ⇒ Object
- #edit_file(path) ⇒ Object
- #file_rename(path, file_name) ⇒ Object
- #format_mb(size) ⇒ Object
- #get_path(path) ⇒ Object
- #get_url(path) ⇒ Object
- #image_resize(file_path) ⇒ Object
- #info_and_preview(file, kind) ⇒ Object
-
#initialize(file, host_url, fc_params = nil, options = {}) ⇒ Connector
constructor
A new instance of Connector.
- #path_to_url(path) ⇒ Object
- #permission_mime(allowed_mime, disallowed_mime) ⇒ Object
- #refresh(path) ⇒ Object
- #set_path(path) ⇒ Object
- #set_type(type) ⇒ Object
- #set_url(path) ⇒ Object
- #thumbs(opt) ⇒ Object
- #upload(upload_files, path) ⇒ Object
Constructor Details
#initialize(file, host_url, fc_params = nil, options = {}) ⇒ Connector
Returns a new instance of Connector.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/fcfinder/connector.rb', line 5 def initialize(file,host_url,fc_params=nil, = {}) #Max dosya boyutu boş ise 1MB dosya yüklemesine izin ver @max_file_size = [:max_file_size] ||= 1_000_000 @allowed_mime = [:allowed_mime] ||= {} @disallowed_mime = [:disallowed_mime] ||= {} #izin verilen dosyalar @permission_mime = (@allowed_mime,@disallowed_mime) @file = file @fcdir = file.chomp('/*') @main_folder = @fcdir.split('/').last @host_url = host_url @main_file = {} if fc_params.nil? @main_params = append_file(file) @main_params[:main_file] = {:path => file.split('/')[-2], :url => file, :sub_dir => @main_file[:sub_dir]} result = [@main_params, @main_params[:directory].size+@main_params[:file].size, format_mb(directory_size(@main_params[:main_file][:url].chomp('/*')))] else result = case fc_params[:type] when 'path_to_url' path_to_url(get_path(fc_params[:path])) #Tum Dosyaları Listele #Klasor Secilme İslemi Yapilinca when 'all_file_list' all_file_list(get_path(fc_params[:url])) #Yeni Klasor Olusturma when 'create_directory' create_directory(fc_params[:path], fc_params[:directory_name]) #Yenileme Islemi when 'refresh' refresh(get_path(fc_params[:path])) #Dosya Indirme Islemi when 'download' download(get_path(fc_params[:path])) #Bilgiler when 'info' info_and_preview(fc_params[:file], fc_params[:kind]) #Onizleme when 'preview' info_and_preview(fc_params[:file], fc_params[:kind]) #Dosya Kopyala when 'copy' copy(get_path(fc_params[:copy_file_path]), get_path(fc_params[:this_folder_path])) #Dosya Zorunlu Kopyala when 'copy!' copy!(get_path(fc_params[:copy_file_path]), get_path(fc_params[:this_folder_path])) #Dosya Kesme when 'cut' cut(get_path(fc_params[:cut_file_path]), get_path(fc_params[:this_folder_path])) #Dosyayı Zorla Kes when 'cut!' cut!(get_path(fc_params[:cut_file_path]), get_path(fc_params[:this_folder_path])) #Dosya Kopyasını Oluşturma when 'duplicate' duplicate(get_path(fc_params[:file_path])) #Dosya Yeniden Adlandır when 'file_rename' file_rename(get_path(fc_params[:path]), fc_params[:file_name]) #Dosya Silme İşlemi when 'delete' delete!(get_path(fc_params[:file_path])) #Dosya Yükleme İşlemi when 'upload' upload(fc_params[:upload], get_path(fc_params[:path])) #Dosya Duzenleme when 'edit_file' edit_file(get_path(fc_params[:file_path])) else # type code here end end @run = result.to_json end |
Instance Attribute Details
#run ⇒ Object (readonly)
Returns the value of attribute run.
3 4 5 |
# File 'lib/fcfinder/connector.rb', line 3 def run @run end |
Instance Method Details
#add_zip_file(path, output_file) ⇒ Object
132 133 134 135 |
# File 'lib/fcfinder/connector.rb', line 132 def add_zip_file(path, output_file) zf = ZipFileGenerator.new(path, output_file) zf.write end |
#all_file_list(url) ⇒ Object
107 108 109 110 |
# File 'lib/fcfinder/connector.rb', line 107 def all_file_list(url) @url_params = append_file(url+'/*') [@url_params,@url_params[:directory].size+@url_params[:file].size,format_mb(directory_size(url))] end |
#append_file(files_url) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/fcfinder/connector.rb', line 379 def append_file(files_url) all_file,all_dir = {},{} Dir.glob(files_url).each do |file| if File.directory?(file) @main_file[:sub_dir] = true if @main_file[:sub_dir].nil? all_dir[file.split('/').last] = {:file=>file,:url => get_url(set_path(file)), :sub_dir => false, :size_2 => directory_size(file), :size => format_mb(directory_size(file)), :ctime => File.ctime(file).strftime('%d/%m/%Y %H:%M'), :path => set_path(file), :type => '_directory'} Dir.glob(file+'/*').each do |sub_dir| if File.directory?(sub_dir) all_dir[file.split('/').last][:sub_dir] = true end end else all_file[file.split('/').last] = {:file=>file, :path => set_path(file), :url => get_url(set_path(file)), :type => set_type(MIME::Types.type_for(file).first.content_type), :size_2 => File.size(file), :size => format_mb(File.size(file)), :ctime => File.ctime(file).strftime('%d/%m/%Y %H:%M')} end end { :directory => all_dir, :file => all_file } end |
#copy(file, target) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/fcfinder/connector.rb', line 216 def copy(file,target) begin file_path = File.join(target,file.split('/').last) if File.exist?(file_path) #0 => Aynı Dosyadan Var result = %w(false 0) else #Kopyalama İşlemini Gerçekleştir FileUtils.cp_r(file,target) thumbs({:file=>file, :target=>target, :type=>:copy}) result = %w(true) end rescue Exception => e result = ['false', '-1',e.to_s] end result end |
#copy!(file, target) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/fcfinder/connector.rb', line 234 def copy!(file,target) begin #Kopyalama İşlemini Gerçekleştir FileUtils.cp_r(file,target) #thumbs'a kopyasını gönder thumbs({:file=>file, :target=>target, :type=>:copy}) result = %w(true) rescue Exception => e result = ['false', '-1',e.to_s] end result end |
#create_directory(path, directory_name) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/fcfinder/connector.rb', line 112 def create_directory(path,directory_name) create_file_path = File.join(get_path(path),directory_name) create_file_thumbs = create_file_path.sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs') if File.exist?(create_file_path) #-1 => Aynı İsimde Dosya Var Dosya Oluşmadı %w(false -1) else if Dir.mkdir(create_file_path) && Dir.mkdir(create_file_thumbs) ['true', {:top_dir => path, :path => set_path(create_file_path)}] else #0 => Herhangibir Hata var Dosya Oluşmadı %w(false 0) end end end |
#cut(file, target) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/fcfinder/connector.rb', line 248 def cut(file,target) begin file_path = target.chomp('/')+'/'+file.split('/').last if File.exist?(file_path) || File.directory?(file_path) #0 => Aynı Dosyadan Var result = %w(false 0) else #Kesme İşlemini Gerçekleştir FileUtils.mv(file,target) #thumbs'a kopyasını gönder thumbs({:file=>file, :target=>target, :type=>:cut}) result = %w(true) end rescue Exception => e result = ['false', '-1',e.to_s] end result end |
#cut!(file, target) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/fcfinder/connector.rb', line 267 def cut!(file,target) begin #Kesme İşlemini Gerçekleştir FileUtils.mv(file,target) #thumbs'a kopyasını gönder thumbs({:file=>file, :target=>target, :type=>:cut}) result = %w(true) rescue Exception => e result = ['false', '-1',e.to_s] end result end |
#delete!(path) ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/fcfinder/connector.rb', line 329 def delete!(path) begin if File.exist?(path) FileUtils.rm_rf(path) FileUtils.rm_rf(path.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')) if File.exist?(path.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')) result = %w(true) else #return false Dosya Yok! result = %w(false 0) end rescue Exception => e result = ['false', '-1',e.to_s] end result end |
#directory_size(path) ⇒ Object
514 515 516 517 518 519 520 521 522 |
# File 'lib/fcfinder/connector.rb', line 514 def directory_size(path) path << '/' unless path.end_with?('/') raise RuntimeError, "#{path} is not a directory" unless File.directory?(path) total_size = 0 Dir["#{path}**/*"].each do |f| total_size += File.size(f) if File.file?(f) && File.size?(f) end total_size end |
#download(path) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/fcfinder/connector.rb', line 137 def download(path) begin if File.directory?(path) output_file = path.chomp('/')+'.zip' add_zip_file(path, output_file) file = set_path(output_file).sub('fcdir:/', '').split('/').join(':') type = path.chomp('/')+'.zip' else file = set_path(path).sub('fcdir:/', '').split('/').join(':') type = path end result = { :file => file, :type => MIME::Types.type_for(type).first.content_type } rescue Exception => e result = ['false', '0',e.to_s] end result end |
#duplicate(file) ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/fcfinder/connector.rb', line 280 def duplicate(file) begin file_path = file.chomp('/') extension = (file_path.split('/').last.split('.').size>1) ? '.'+file_path.split('/').last.split('.').last : '' file_name = file_path.split('/').last.chomp(extension) folder_name = file_path.chomp(file_path.split('/').last).chomp('/') reg_file = "#{file_name}".match(/(.+?) copy ([0-9])/i) if reg_file.nil? && !File.exist?(folder_name+'/'+file_name+' copy 1'+extension) FileUtils.cp_r(file_path, folder_name+'/'+file_name+' copy 1'+extension) #thumbs dosyaları ekle thumbs({:file_path=>file_path,:file=>file_path,:type=>:duplicate,:folder_name=>folder_name,:file_name=>file_name,:extension=>extension}) result = %w(true) else #"file_name copy 1" şeklinde bir dosya adı var reg_file = "#{file_name} copy 1#{extension}".match(/(.+?) copy ([0-9])/i) if reg_file.nil? j = Dir.glob("#{folder_name}/#{reg_file[1]} copy *#{extension}").last.match(/#{reg_file[1]} copy ([0-9])#{extension}/)[1].to_i + 1 new_file_name = "#{reg_file[1]} copy #{j}#{extension}" new_file_path = folder_name.chomp('/')+'/'+new_file_name FileUtils.cp_r(file_path, new_file_path) #thumbs'a kopyasını gönder thumbs({:file_path=>file_path,:file=>file_path,:type=>:duplicate2,:new_file_path=>new_file_path}) result = %w(true) end rescue Exception => e result = ['false', '-1',e.to_s] end result end |
#edit_file(path) ⇒ Object
373 374 375 376 377 |
# File 'lib/fcfinder/connector.rb', line 373 def edit_file(path) File.exist?(path) ? { :url => get_url(set_path(path)), :title => path.chomp('/').split('/').last } : %w(false 0) end |
#file_rename(path, file_name) ⇒ Object
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/fcfinder/connector.rb', line 311 def file_rename(path,file_name) begin if File.exist?(path) folder_name = path.chomp(path.split('/').last).chomp('/') FileUtils.mv(path,folder_name+'/'+file_name) #thumbs'a kopyasını gönder thumbs({:file=>path,:target=>path,:type=>:rename,:folder_name=>folder_name,:file_name=>file_name}) result = %w(true) else #return false Dosya Yok! result = %w(false) end rescue Exception => e result = ['false', '-1',e.to_s] end result end |
#format_mb(size) ⇒ Object
525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/fcfinder/connector.rb', line 525 def format_mb(size) conv = %w(B KB MB GB TER PB EB) scale = 1024 ndx=1 return "#{(size)} #{conv[ndx-1]}" if size < 2*(scale**ndx) size=size.to_f [2,3,4,5,6,7].each do |ndx| return "#{'%.3f' % (size/(scale**(ndx-1)))} #{conv[ndx-1]}" if size < 2*(scale**ndx) end ndx=7 "#{'%.3f' % (size/(scale**(ndx-1)))} #{conv[ndx-1]}" end |
#get_path(path) ⇒ Object
403 404 405 |
# File 'lib/fcfinder/connector.rb', line 403 def get_path(path) path.chomp('/').sub('fcdir:',@fcdir) end |
#get_url(path) ⇒ Object
413 414 415 |
# File 'lib/fcfinder/connector.rb', line 413 def get_url(path) path.chomp('/').sub('fcdir:',File.join(@host_url,@main_folder)) end |
#image_resize(file_path) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/fcfinder/connector.rb', line 197 def image_resize(file_path) file_path.each do |file| #ORJ=>thumbs = file.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs').chomp(file.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs').split('/').last).chomp('/') thumbs = file.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs').chomp(file.split('/').last).chomp('/') unless File.exist?(thumbs) _folder = '' thumbs.split('/').each do |folder| _folder << folder + '/' unless File.exist?(_folder) Dir.mkdir(_folder.chomp('/')) end end end image = MiniMagick::Image.open(file) image.resize '64x64' image.write(file.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')) end end |
#info_and_preview(file, kind) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/fcfinder/connector.rb', line 155 def info_and_preview(file,kind) { :url => get_url(file), :path => file, :size => kind=='directory' ? format_mb(directory_size(get_path(file))) : format_mb(File.size(get_path(file))), :ctime => File.ctime(get_path(file)).strftime('%d/%m/%Y %H:%M'), :mtime => File.mtime(get_path(file)).strftime('%d/%m/%Y %H:%M'), :type => File.directory?(get_path(file)) ? 'directory' : set_type(MIME::Types.type_for(get_path(file)).first.content_type) , :mime_type => File.directory?(get_path(file)) ? 'directory' : MIME::Types.type_for(get_path(file)).first.content_type , :permissions => {:write => File.writable?(get_path(file)).to_s, :read => File.readable?(get_path(file)).to_s} } end |
#path_to_url(path) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/fcfinder/connector.rb', line 98 def path_to_url(path) if File.exist?(path) ['true',get_url(set_path(path))] else %w(false 0) end end |
#permission_mime(allowed_mime, disallowed_mime) ⇒ Object
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/fcfinder/connector.rb', line 539 def (allowed_mime,disallowed_mime) = { 'doc' => 'application/vnd.ms-word', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'xls' => 'application/vnd.ms-excel', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'ppt' => 'application/vnd.ms-powerpoint', 'pps' => 'application/vnd.ms-powerpoint', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'pdf' => 'application/pdf', 'xml' => 'application/xml', 'swf' => 'application/x-shockwave-flash', # archives 'gz' => 'application/x-gzip', 'tgz' => 'application/x-gzip', 'bz' => 'application/x-bzip2', 'bz2' => 'application/x-bzip2', 'tbz' => 'application/x-bzip2', 'zip' => 'application/zip', 'rar' => 'application/x-rar', 'tar' => 'application/x-tar', #'rar' => 'application/x-rar-compressed', '7z' => 'application/x-7z-compressed', # texts 'txt' => 'text/plain', 'php' => 'text/x-php', 'html' => 'text/html', 'htm' => 'text/html', 'js' => 'text/javascript', 'css' => 'text/css', 'rtf' => 'text/rtf', 'rtfd' => 'text/rtfd', 'py' => 'text/x-python', 'java' => 'text/x-java-source', 'rb' => 'text/x-ruby', 'erb' => 'text/x-ruby', 'sh' => 'text/x-shellscript', 'pl' => 'text/x-perl', 'sql' => 'text/x-sql', # images 'bmp' => 'image/x-ms-bmp', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'tga' => 'image/x-targa', 'psd' => 'image/vnd.adobe.photoshop', 'ico' => 'image/x-icon', # audio 'mp3' => 'audio/mpeg', 'mid' => 'audio/midi', 'ogg' => 'audio/ogg', 'mp4a' => 'audio/mp4', 'wav' => 'audio/wav', 'wma' => 'audio/x-ms-wma', # video 'avi' => 'video/x-msvideo', 'dv' => 'video/x-dv', 'mp4' => 'video/mp4', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mov' => 'video/quicktime', 'wm' => 'video/x-ms-wmv', 'flv' => 'video/x-flv', 'mkv' => 'video/x-matroska' } .merge!(allowed_mime) .delete_if {|key| disallowed_mime.include?(key) } end |
#refresh(path) ⇒ Object
128 129 130 |
# File 'lib/fcfinder/connector.rb', line 128 def refresh(path) append_file(File.join(path,'/*')) end |
#set_path(path) ⇒ Object
398 399 400 |
# File 'lib/fcfinder/connector.rb', line 398 def set_path(path) path.chomp('/').sub(@fcdir, 'fcdir:') end |
#set_type(type) ⇒ Object
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/fcfinder/connector.rb', line 418 def set_type(type) case type when 'application/vnd.ms-word' 'doc' when 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' 'docx' when 'application/vnd.ms-excel' 'xls' when 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' 'xlsx' when 'application/vnd.openxmlformats-officedocument.presentationml.presentation' 'pptx' when 'application/vnd.ms-powerpoint' 'ppt' when 'application/pdf' 'pdf' when 'application/xml' 'xml' when 'application/x-shockwave-flash' 'swf' when 'application/x-gzip', 'application/gzip' 'gz' when 'application/x-gtar' 'tgz' when 'application/x-bzip' 'bz' when 'application/x-bzip2' 'bz2' when 'application/zip' 'zip' when 'application/x-rar', 'application/x-rar-compressed' 'rar' when 'application/x-tar' 'tar' when 'application/x-7z-compressed' '7z' when 'text/plain' 'txt' when 'text/x-php', 'application/x-httpd-php' 'php' when 'text/html' 'html' when 'text/htm' 'htm' when 'application/javascript' 'js' when 'text/css' 'css' when 'application/x-ruby' 'rb' when 'image/tiff' 'tiff' when 'image/x-targa' 'tga' when 'image/vnd.adobe.photoshop' 'psd' when 'image/x-icon' 'ico' when 'audio/mpeg' 'mp3' when 'audio/midi' 'mid' when 'audio/ogg' 'ogg' when 'audio/mp4' 'mp4a' when 'audio/wav', 'audio/x-wav' 'wav' when 'audio/x-ms-wma' 'vma' when 'video/x-msvideo' 'avi' when 'video/x-dv' 'dv' when 'video/mp4' 'mp4' when 'video/mpeg' 'mpeg' when 'video/mpeg' 'mpg' when 'video/quicktime' 'mov' when 'video/x-ms-wmv' 'vm' when 'video/x-flv' 'flv' when 'video/x-matroska' 'mkv' when 'image/png', 'image/jpeg','image/x-ms-bmp','image/gif' 'image_file' else 'other' end end |
#set_url(path) ⇒ Object
408 409 410 |
# File 'lib/fcfinder/connector.rb', line 408 def set_url(path) path.chomp('/').sub(File.join(@host_url,@main_folder)+@main_folder, 'fcdir:') end |
#thumbs(opt) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/fcfinder/connector.rb', line 167 def thumbs(opt) thumbs = '' thumbs = opt[:target].sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs') if opt[:type] == :cut || opt[:type] == :copy || opt[:type] == :rename thumbs = opt[:file_path].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs') if opt[:type] == :duplicate || opt[:type] == :duplicate2 if File.directory?(opt[:file]) FileUtils.cp_r(opt[:file].sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs'),thumbs) if opt[:type ] == :copy FileUtils.mv(opt[:file].sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs'),thumbs) if opt[:type ] == :cut FileUtils.cp_r(thumbs, opt[:folder_name].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')+'/'+opt[:file_name]+' copy 1'+opt[:extension]) if opt[:type ] == :duplicate FileUtils.cp_r(thumbs, opt[:new_file_path].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')) if opt[:type2] == :duplicate2 FileUtils.mv(thumbs, File.join(opt[:folder_name].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs'),opt[:file_name])) if opt[:type] == :rename else if %w(image/x-ms-bmp image/jpeg image/gif image/png).include?(MIME::Types.type_for(opt[:file]).first.content_type) unless File.exist?(thumbs) _folder = '' thumbs.split('/').each do |folder| _folder << folder+'/' unless File.exist?(_folder) Dir.mkdir(_folder.chomp('/')) end end end FileUtils.cp_r(opt[:file].sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs'),thumbs) if opt[:type] == :copy FileUtils.mv(opt[:file].sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs'),thumbs) if opt[:type] == :cut FileUtils.cp_r(thumbs, opt[:folder_name].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')+'/'+opt[:file_name]+' copy 1'+opt[:extension]) if opt[:type] == :duplicate FileUtils.cp_r(thumbs, opt[:new_file_path].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')) if opt[:type] == :duplicate2 FileUtils.mv(thumbs, File.join(opt[:folder_name].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs'),opt[:file_name])) if opt[:type] == :rename end end end |
#upload(upload_files, path) ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/fcfinder/connector.rb', line 345 def upload(upload_files,path) begin image_mime_type = %w(image/x-ms-bmp image/jpeg image/gif image/png) file_path,error_delete_file = [],[] upload_files.each do |file| #dosya büyük return ['false', '0',format_mb(@max_file_size)] if file.tempfile.size > @max_file_size #format yok return ['false', '-1',@permission_mime.to_a] unless @permission_mime.has_key?(file.original_filename.split('.').last) || @permission_mime[file.original_filename.split('.').last]==file.content_type file_path.push(File.join(path,file.original_filename)) if image_mime_type.include?(file.content_type) error_delete_file.push(File.join(path,file.original_filename)) File.open(File.join(path,file.original_filename), 'wb') do |f| f.write(file.read) end end # resimleri yeniden boyutlandır image_resize(file_path) result = %w(true) rescue Exception => e error_delete_file.each do |file| FileUtils.rm_rf(file) unless File.size(file) > 0 end result = ['false', '-2',e.to_s] end result end |