File tree Expand file tree Collapse file tree 7 files changed +513
-315
lines changed
thumbly-http-client/src/main/java/org/code13k/thumbly/web/client
thumbly-image-info/src/main/java/org/code13k/thumbly/image/info
thumbly-image-processor/src/main/java/org/code13k/thumbly/image/processor
thumbly-main/src/main/java/org/code13k/thumbly/service Expand file tree Collapse file tree 7 files changed +513
-315
lines changed Original file line number Diff line number Diff line change @@ -114,7 +114,10 @@ The other is a restful API server that provide application information and addit
114114# # Main HTTP Server
115115# ## Usage
116116` ` ` html
117+ http://example.com:{port}/{secret_path}
117118http://example.com:{port}/{command}/{channel}/{path}
119+ http://example.com:{port}/status/{secret_path}
120+ http://example.com:{port}/status/{command}/{channel}/{path}
118121` ` `
119122* port
120123 * Server port
@@ -134,6 +137,8 @@ http://example.com:{port}/{command}/{channel}/{path}
134137 * It's *channel* in channel_config.yml
135138* path
136139 * Origin path
140+ * status
141+ * Check if thumbnail is generated and cached in disk.
137142
138143# ## Example
139144` ` ` html
Original file line number Diff line number Diff line change 22
33
44import org .apache .commons .codec .digest .DigestUtils ;
5+ import org .apache .commons .io .FileUtils ;
56import org .apache .commons .io .FilenameUtils ;
67import org .apache .commons .lang3 .StringUtils ;
78import org .code13k .thumbly .web .client .model .WebData ;
89import org .slf4j .Logger ;
910import org .slf4j .LoggerFactory ;
1011
12+ import java .nio .file .Files ;
13+ import java .nio .file .Paths ;
1114import java .util .ArrayList ;
1215import java .util .HashMap ;
1316import java .util .List ;
@@ -103,6 +106,21 @@ public void accept(String filePath) {
103106 });
104107 }
105108
109+ /**
110+ * Get cached file
111+ */
112+ public String getCachedFile (String url ){
113+ WebData cachedWebData = getCache (url );
114+ if (cachedWebData !=null ){
115+ String cachedFilePath = cachedWebData .getFilePath ();
116+ boolean result = Files .exists (Paths .get (cachedFilePath ));
117+ if (result == true ) {
118+ return cachedFilePath ;
119+ }
120+ }
121+ return null ;
122+ }
123+
106124 /**
107125 * Size of cache directory
108126 */
Original file line number Diff line number Diff line change @@ -111,6 +111,20 @@ public void accept(ImageInfo imageInfo) {
111111 });
112112 }
113113
114+ /**
115+ * Get cached image info
116+ */
117+ public ImageInfo getCached (String filePath ){
118+ final String key = Util .MD5FromFile (filePath );
119+ ImageInfo imageInfo = ImageInfoStore .getInstance ().get (key );
120+ mLogger .trace ("key = " + key );
121+
122+ if (imageInfo != null ) {
123+ return imageInfo ;
124+ }
125+ return null ;
126+ }
127+
114128 /**
115129 * Size of cached info
116130 */
Original file line number Diff line number Diff line change @@ -153,10 +153,36 @@ public void accept(String tempThumbFilePath) {
153153 });
154154 }
155155
156+ /**
157+ * Get cached file
158+ */
159+ public String getCachedFile (String originFilePath , Command command ) {
160+ // Get cached image info
161+ ImageInfo cachedImageInfo = CachedImageInfo .getInstance ().getCached (originFilePath );
162+ if (cachedImageInfo != null ) {
163+ // Calculate output size
164+ Size outputSize = calculateOutputSize (cachedImageInfo , command );
165+ if (outputSize != null ) {
166+ // Process
167+ Command newCommand = new Command ();
168+ newCommand .fromCommand (command );
169+ newCommand .setSize (outputSize );
170+ // Get thumbnail
171+ final String key = generateKey (originFilePath , newCommand );
172+ String thumbFilePath = FileStore .getInstance ().getCacheFile (key );
173+ // End
174+ if (StringUtils .isEmpty (thumbFilePath ) == false ) {
175+ return thumbFilePath ;
176+ }
177+ }
178+ }
179+ return null ;
180+ }
181+
156182 /**
157183 * Operation count in queue
158184 */
159- public int operationCountInQueue (){
185+ public int operationCountInQueue () {
160186 return mOperator .count ();
161187 }
162188
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public class ApiHttpServer extends AbstractVerticle {
3636
3737
3838 /**
39- * start()
39+ * Start
4040 */
4141 @ Override
4242 public void start () throws Exception {
You can’t perform that action at this time.
0 commit comments