Search in sources :

Example 1 with FileSystemObjectResolver

use of org.vitrivr.cineast.api.rest.resolvers.FileSystemObjectResolver in project cineast by vitrivr.

the class APIEndpoint method registerServingRoutes.

/**
 * If configured, this registers two special routes that serve the media objects as media content and additionally a thumbnails endpoint for them.
 */
private void registerServingRoutes(final Javalin service, final APIConfig config) {
    if (config.getServeContent()) {
        service.get("/thumbnails/{id}", new ResolvedContentRoute(new FileSystemThumbnailResolver(new File(Config.sharedConfig().getApi().getThumbnailLocation()))));
        /* The VBS database in-use is broken, this is the hack to circumvent object paths being wrong */
        FileSystemObjectResolver fsor;
        if (config.isObjectsFilesAreIDed()) {
            fsor = new FileSystemObjectResolver(new File(Config.sharedConfig().getApi().getObjectLocation()), new MediaObjectReader(Config.sharedConfig().getDatabase().getSelectorSupplier().get()), ((baseDir, object) -> {
                // String ext = object.getPath().substring(object.getPath().lastIndexOf('.'));
                String ext = "." + Config.sharedConfig().getApi().getVideoExtension();
                return new File(baseDir, object.getObjectId() + ext);
            }));
        } else {
            fsor = new FileSystemObjectResolver(new File(Config.sharedConfig().getApi().getObjectLocation()), new MediaObjectReader(Config.sharedConfig().getDatabase().getSelectorSupplier().get()));
        }
        service.get("/objects/{id}", new ResolvedContentRoute(fsor));
    }
}
Also used : FileSystemObjectResolver(org.vitrivr.cineast.api.rest.resolvers.FileSystemObjectResolver) FileSystemThumbnailResolver(org.vitrivr.cineast.api.rest.resolvers.FileSystemThumbnailResolver) ResolvedContentRoute(org.vitrivr.cineast.api.rest.routes.ResolvedContentRoute) MediaObjectReader(org.vitrivr.cineast.core.db.dao.reader.MediaObjectReader) File(java.io.File)

Aggregations

File (java.io.File)1 FileSystemObjectResolver (org.vitrivr.cineast.api.rest.resolvers.FileSystemObjectResolver)1 FileSystemThumbnailResolver (org.vitrivr.cineast.api.rest.resolvers.FileSystemThumbnailResolver)1 ResolvedContentRoute (org.vitrivr.cineast.api.rest.routes.ResolvedContentRoute)1 MediaObjectReader (org.vitrivr.cineast.core.db.dao.reader.MediaObjectReader)1