This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
45 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
converters/src/main/java/org/dukecon/server/convert/DoagSpeakerImageService.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.dukecon.server.convert | ||
|
||
import groovy.util.logging.Slf4j | ||
import org.dukecon.adapter.ResourceWrapper | ||
import org.dukecon.server.conference.SpeakerImageService | ||
|
||
import java.security.MessageDigest | ||
|
||
@Slf4j | ||
class DoagSpeakerImageService implements SpeakerImageService { | ||
|
||
private final String path | ||
|
||
DoagSpeakerImageService(String path) { | ||
this.path = path | ||
} | ||
|
||
String addImage(byte[] content, String filename = null) { | ||
return this.addImage(Base64.encoder.encodeToString(content), filename) | ||
} | ||
|
||
String addImage(String contentBase64, String filename = null) { | ||
log.trace("Adding speaker image from '{}')", filename ? "file >${filename}<" : "Image Data: >${contentBase64?.substring(0, 10)}<") | ||
|
||
String md5Hash = md5(contentBase64) | ||
|
||
//create image resource | ||
def final image = new ImageWithName("${md5Hash}.${fileEnding(contentBase64)}", Base64.decoder.decode(contentBase64)) | ||
|
||
//write image resource to file | ||
def pathInFilesystem = new File(this.path) | ||
if(!pathInFilesystem.exists()) | ||
pathInFilesystem.mkdir() | ||
image.writeToDisk(this.path) | ||
|
||
return md5Hash | ||
} | ||
|
||
@Override | ||
SpeakerImageService.ImageWithName getImage(String md5Hash) { | ||
throw new IllegalStateException("should not be called from converter") | ||
} | ||
|
||
private md5(String s) { | ||
MessageDigest digest = MessageDigest.getInstance("MD5") | ||
digest.update(s.bytes); | ||
new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') | ||
} | ||
|
||
private fileEnding(String content) { | ||
switch (content) { | ||
case ~/^iVBO.*/: | ||
return 'png' | ||
case ~/^R0.*/: | ||
return 'gif' | ||
case ~$/^/9j/*/$: | ||
default: | ||
return 'jpg' | ||
} | ||
} | ||
@Override | ||
Map<String, SpeakerImageService.ImageWithName> getImages() { | ||
throw new IllegalStateException("should not be called from converter") | ||
} | ||
} | ||
40 changes: 0 additions & 40 deletions
40
converters/src/main/java/org/dukecon/server/convert/DummySpeakerImageService.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +0,0 @@ | ||
package org.dukecon.server.convert | ||
|
||
import org.dukecon.server.conference.SpeakerImageService | ||
|
||
/** | ||
* Will be obsolete as soon as conference provider will be disabled in dukecon_server implementation. This interface and | ||
* its references can be removed when speaker images will be saved as static files. | ||
*/ | ||
@Deprecated | ||
class DummySpeakerImageService implements SpeakerImageService { | ||
@Override | ||
Map<String, ImageWithName> getImages() { | ||
return null | ||
} | ||
|
||
@Override | ||
String addImage(byte ... content) { | ||
return null | ||
} | ||
|
||
@Override | ||
String addImage(byte[] content, String filename) { | ||
return null | ||
} | ||
|
||
@Override | ||
String addImage(String contentBase64) { | ||
return null | ||
} | ||
|
||
@Override | ||
String addImage(String contentBase64, String filename) { | ||
return null | ||
} | ||
|
||
@Override | ||
ImageWithName getImage(String md5Hash) { | ||
return null | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters