1+ require "imagekitio/railtie"
2+
3+ require 'carrierwave'
4+ require 'base64'
5+ require_relative './carrierwave/storage/imagekit_store'
6+ require_relative './carrierwave/storage/ik_file'
7+ require_relative './carrierwave/support/uri_filename'
8+ require_relative './imagekit/imagekit.rb'
9+ require_relative "./imagekit/resource"
10+ require_relative "./imagekit/file"
11+ require_relative "./imagekit/url"
12+ require_relative "./imagekit/utils/calculation"
13+
14+ module CarrierWave
15+ module Uploader
16+ class Base
17+
18+ def initialize ( *)
19+ ik_config = Rails . application . config . imagekit
20+ @imagekit = ImageKit ::ImageKitClient . new ( ik_config [ :private_key ] , ik_config [ :public_key ] , ik_config [ :url_endpoint ] )
21+ @options = { }
22+ end
23+
24+ configure do |config |
25+ config . storage_engines [ :imagekit_store ] = 'CarrierWave::Storage::ImageKitStore'
26+ end
27+
28+ def filename
29+ if options !=nil
30+ @options = options
31+ end
32+ if self . file !=nil
33+ base64 = Base64 . encode64 ( ::File . open ( self . file . file , "rb" ) . read )
34+ resp = @imagekit . upload_file ( open ( self . file . file , 'rb' ) , self . file . filename , @options )
35+ ::File . delete ( self . file . file )
36+ res = resp [ :response ] . to_json
37+ if res !="null"
38+ res
39+ else
40+ "{\" filePath\" :\" \" ,\" url\" :\" \" ,\" name\" :\" \" }"
41+ end
42+ else
43+ "{\" filePath\" :\" \" ,\" url\" :\" \" ,\" name\" :\" \" }"
44+ end
45+ end
46+
47+ def fileId
48+ JSON . parse ( self . identifier ) [ 'fileId' ]
49+ end
50+
51+ def blob
52+ JSON . parse ( self . identifier )
53+ end
54+
55+ def url_with ( opt )
56+ path = JSON . parse ( self . identifier ) [ 'filePath' ]
57+ opt [ :path ] = path
58+ url = @imagekit . url ( opt )
59+ end
60+
61+ def url
62+ JSON . parse ( self . identifier ) [ 'url' ]
63+ end
64+
65+ def options
66+ options = { }
67+ end
68+ end
69+
70+ end
71+
72+ end
0 commit comments