Skip to content

Commit b3c9ede

Browse files
committed
[#2] Check if thumbnail is generated and cached in disk.
1 parent 645fe5e commit b3c9ede

File tree

7 files changed

+513
-315
lines changed

7 files changed

+513
-315
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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}
117118
http://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

thumbly-http-client/src/main/java/org/code13k/thumbly/web/client/CachedWebClient.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33

44
import org.apache.commons.codec.digest.DigestUtils;
5+
import org.apache.commons.io.FileUtils;
56
import org.apache.commons.io.FilenameUtils;
67
import org.apache.commons.lang3.StringUtils;
78
import org.code13k.thumbly.web.client.model.WebData;
89
import org.slf4j.Logger;
910
import org.slf4j.LoggerFactory;
1011

12+
import java.nio.file.Files;
13+
import java.nio.file.Paths;
1114
import java.util.ArrayList;
1215
import java.util.HashMap;
1316
import 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
*/

thumbly-image-info/src/main/java/org/code13k/thumbly/image/info/CachedImageInfo.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*/

thumbly-image-processor/src/main/java/org/code13k/thumbly/image/processor/CachedImageProcessor.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff 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

thumbly-main/src/main/java/org/code13k/thumbly/service/api/ApiHttpServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)