mirror of
https://github.com/simon987/sist2.git
synced 2025-12-12 15:08:53 +00:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| efdde2734e | |||
| 66658fa8f7 | |||
| df41c251e4 | |||
| 3282ab56ba | |||
| 8300838d30 | |||
| c9870a6d3d | |||
| a143cc4fcf | |||
| 9ef1f3781d | |||
| bbee8aa721 | |||
| d22f83c797 | |||
| 50615486a4 | |||
| ca79e4f797 | |||
| 6a9fd08a80 | |||
| cab890dc9b | |||
| b3c4faf2df | |||
| 353937171a | |||
| c80002bea4 | |||
| 56adee9d81 | |||
| d6493d6d5f | |||
| 0967e9676d | |||
| 487e998ea0 | |||
| 919f45c79c | |||
| d42129cfcb | |||
| 754983e34a |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -40,3 +40,6 @@
|
||||
[submodule "lib/libtiff"]
|
||||
path = lib/libtiff
|
||||
url = https://gitlab.com/libtiff/libtiff
|
||||
[submodule "lib/libpng"]
|
||||
path = lib/libpng
|
||||
url = https://github.com/glennrp/libpng
|
||||
|
||||
@@ -45,7 +45,6 @@ add_executable(
|
||||
find_package(PkgConfig REQUIRED)
|
||||
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig/")
|
||||
|
||||
#find_package(OpenSSL REQUIRED)
|
||||
find_package(Freetype REQUIRED)
|
||||
|
||||
pkg_check_modules(GLIB REQUIRED glib-2.0)
|
||||
@@ -84,7 +83,8 @@ target_link_directories(
|
||||
target_compile_options(sist2
|
||||
PRIVATE
|
||||
-Ofast
|
||||
# -march=native
|
||||
# -march=native
|
||||
-fPIC
|
||||
-fno-stack-protector
|
||||
-fomit-frame-pointer
|
||||
)
|
||||
@@ -111,7 +111,7 @@ TARGET_LINK_LIBRARIES(
|
||||
${PROJECT_SOURCE_DIR}/lib/libonion_static.a
|
||||
|
||||
pthread
|
||||
curl
|
||||
|
||||
m
|
||||
bz2
|
||||
${PROJECT_SOURCE_DIR}/lib/libmagic.a
|
||||
@@ -128,8 +128,14 @@ TARGET_LINK_LIBRARIES(
|
||||
${PROJECT_SOURCE_DIR}/lib/libtesseract.a
|
||||
${PROJECT_SOURCE_DIR}/lib/liblept.a
|
||||
${PROJECT_SOURCE_DIR}/lib/libtiff.a
|
||||
png
|
||||
${PROJECT_SOURCE_DIR}/lib/libpng16.a
|
||||
stdc++
|
||||
|
||||
# curl
|
||||
${PROJECT_SOURCE_DIR}/lib/libcurl.a
|
||||
${PROJECT_SOURCE_DIR}/lib/libcrypto.a
|
||||
${PROJECT_SOURCE_DIR}/lib/libssl.a
|
||||
dl
|
||||
)
|
||||
|
||||
add_custom_target(
|
||||
|
||||
@@ -16,4 +16,7 @@ RUN mkdir -p /usr/share/tessdata && \
|
||||
|
||||
ADD sist2 /root/sist2
|
||||
|
||||
ENV LANG C.UTF-8
|
||||
ENV LC_ALL C.UTF-8
|
||||
|
||||
ENTRYPOINT ["/root/sist2"]
|
||||
|
||||
@@ -5,6 +5,11 @@ strip sist2
|
||||
version=$(./sist2 --version)
|
||||
|
||||
echo "Version ${version}"
|
||||
docker build . -t simon987/sist2:${version} -t simon987/sist2:latest
|
||||
docker build . -t simon987/sist2:${version} -t simon987/sist2:latest \
|
||||
-t docker.pkg.github.com/simon987/sist2/sist2:latest -t docker.pkg.github.com/simon987/sist2/sist2:${version}
|
||||
docker push simon987/sist2:${version}
|
||||
docker push simon987/sist2:latest
|
||||
docker push docker.pkg.github.com/simon987/sist2/sist2:latest
|
||||
docker push docker.pkg.github.com/simon987/sist2/sist2:${version}
|
||||
|
||||
docker run --rm -it simon987/sist2 -v
|
||||
@@ -29,7 +29,7 @@ sist2 (Simple incremental search tool)
|
||||
1. Have an [Elasticsearch](https://www.elastic.co/downloads/elasticsearch) instance running
|
||||
1.
|
||||
1. Download the [latest sist2 release](https://github.com/simon987/sist2/releases) *
|
||||
1. *(or)* Download an [development snapshot](https://files.simon987.net/artifacts/Sist2/Build/) *(Not recommended!)*
|
||||
1. *(or)* Download a [development snapshot](https://files.simon987.net/artifacts/Sist2/Build/) *(Not recommended!)*
|
||||
1. *(or)* `docker pull simon987/sist2:latest`
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ sist2 (Simple incremental search tool)
|
||||
|
||||
## Example usage
|
||||
|
||||
|
||||

|
||||
|
||||
See help page `sist2 --help` for more details.
|
||||
|
||||
**Scan a directory**
|
||||
|
||||
@@ -5,4 +5,3 @@
|
||||
cmake .
|
||||
make
|
||||
strip sist2
|
||||
strip sist2_scan
|
||||
|
||||
Binary file not shown.
Binary file not shown.
1
lib/libpng
Submodule
1
lib/libpng
Submodule
Submodule lib/libpng added at 301f7a1429
@@ -7,7 +7,7 @@
|
||||
},
|
||||
"suggest-path": {
|
||||
"type": "completion",
|
||||
"analyzer": "keyword"
|
||||
"analyzer": "case_insensitive_kw_analyzer"
|
||||
},
|
||||
"mime": {
|
||||
"type": "keyword"
|
||||
|
||||
@@ -21,6 +21,12 @@
|
||||
"lowercase"
|
||||
]
|
||||
},
|
||||
"case_insensitive_kw_analyzer": {
|
||||
"tokenizer": "keyword",
|
||||
"filter": [
|
||||
"lowercase"
|
||||
]
|
||||
},
|
||||
"my_nGram": {
|
||||
"tokenizer": "my_nGram_tokenizer",
|
||||
"filter": [
|
||||
|
||||
@@ -5,7 +5,7 @@ THREADS=$(nproc)
|
||||
cd lib
|
||||
|
||||
cd mupdf
|
||||
make USE_SYSTEM_HARFBUZZ=yes USE_SYSTEM_OPENJPEG=yes HAVE_X11=no HAVE_GLUT=no -j $THREADS
|
||||
CFLAGS=-fPIC make USE_SYSTEM_HARFBUZZ=yes USE_SYSTEM_OPENJPEG=yes HAVE_X11=no HAVE_GLUT=no -j $THREADS
|
||||
cd ..
|
||||
|
||||
mv mupdf/build/release/libmupdf.a .
|
||||
@@ -13,8 +13,7 @@ mv mupdf/build/release/libmupdf-third.a .
|
||||
|
||||
# openjp2
|
||||
cd openjpeg
|
||||
#cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3 -march=native -DNDEBUG"
|
||||
cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3"
|
||||
cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3 -march=native -DNDEBUG -fPIC"
|
||||
make -j $THREADS
|
||||
cd ..
|
||||
mv openjpeg/bin/libopenjp2.a .
|
||||
@@ -22,7 +21,7 @@ mv openjpeg/bin/libopenjp2.a .
|
||||
# harfbuzz
|
||||
cd harfbuzz
|
||||
./autogen.sh
|
||||
./configure --disable-shared --enable-static
|
||||
CFLAGS=-fPIC ./configure --disable-shared --enable-static
|
||||
make -j $THREADS
|
||||
cd ..
|
||||
mv harfbuzz/src/.libs/libharfbuzz.a .
|
||||
@@ -33,7 +32,8 @@ cd ffmpeg
|
||||
--disable-ffprobe --disable-doc\
|
||||
--disable-manpages --disable-postproc --disable-avfilter \
|
||||
--disable-alsa --disable-lzma --disable-xlib --disable-debug\
|
||||
--disable-vdpau --disable-vaapi --disable-sdl2 --disable-network
|
||||
--disable-vdpau --disable-vaapi --disable-sdl2 --disable-network\
|
||||
--extra-cflags=-fPIC
|
||||
make -j $THREADS
|
||||
cd ..
|
||||
|
||||
@@ -74,7 +74,8 @@ mv libmagic/src/.libs/libmagic.a .
|
||||
cd tesseract
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DSTATIC=on -DBUILD_TRAINING_TOOLS=off ..
|
||||
cmake -DSTATIC=on -DBUILD_TRAINING_TOOLS=off -DBUILD_TESTS=off -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_CXX_FLAGS="-fPIC" ..
|
||||
make -j $THREADS
|
||||
cd ../..
|
||||
mv tesseract/build/libtesseract.a .
|
||||
@@ -82,7 +83,7 @@ mv tesseract/build/libtesseract.a .
|
||||
# leptonica
|
||||
cd leptonica
|
||||
./autogen.sh
|
||||
./configure --without-zlib --without-jpeg --without-giflib \
|
||||
CFLAGS="-fPIC" ./configure --without-zlib --without-jpeg --without-giflib \
|
||||
--without-giflib --without-libwebp --without-libwebpmux --without-libopenjpeg \
|
||||
--enable-static --disable-shared
|
||||
make -j $THREADS
|
||||
@@ -92,8 +93,36 @@ mv leptonica/src/.libs/liblept.a .
|
||||
# tiff
|
||||
cd libtiff
|
||||
./autogen.sh
|
||||
./configure --enable-static --disable-shared --disable-lzw --disable-jpeg --disable-webp \
|
||||
CFLAGS="-fPIC" CXXFLAGS="-fPIC" CXX_FLAGS="-fPIC" ./configure --enable-static --disable-shared --disable-lzw --disable-jpeg --disable-webp \
|
||||
--disable-lzma --disable-zstd --disable-jbig
|
||||
make -j $THREADS
|
||||
cd ..
|
||||
mv libtiff/libtiff/.libs/libtiff.a .
|
||||
mv libtiff/libtiff/.libs/libtiff.a .
|
||||
|
||||
# png
|
||||
cd libpng
|
||||
CFLAGS="-fPIC" ./configure --enable-static --disable-shared
|
||||
make -j $THREADS
|
||||
cd ..
|
||||
mv libpng/.libs/libpng16.a .
|
||||
|
||||
# openssl...
|
||||
git clone --depth 1 -b OpenSSL_1_1_0-stable https://github.com/openssl/openssl
|
||||
cd openssl
|
||||
./config --prefix=$(pwd)/../ssl
|
||||
make depend
|
||||
make -j $THREADS
|
||||
make install
|
||||
cd ..
|
||||
mv ./openssl/libcrypto.a ./openssl/libssl.a .
|
||||
|
||||
# curl
|
||||
wget -nc https://curl.haxx.se/download/curl-7.68.0.tar.gz
|
||||
tar -xzf curl-7.68.0.tar.gz
|
||||
cd curl-7.68.0
|
||||
./configure --disable-ldap --disable-ldaps --without-librtmp --disable-rtsp --disable-crypto-auth \
|
||||
--disable-smtp --without-libidn2 --without-nghttp2 --without-brotli --enable-static --disable-shared \
|
||||
--without-libpsl --with-ssl=$(pwd)/../ssl
|
||||
make -j $THREADS
|
||||
cd ..
|
||||
mv curl-7.68.0/lib/.libs/libcurl.a .
|
||||
|
||||
22
src/cli.c
22
src/cli.c
@@ -15,6 +15,13 @@
|
||||
#define DEFAULT_BIND_ADDR "localhost"
|
||||
#define DEFAULT_PORT "4090"
|
||||
|
||||
const char* TESS_DATAPATHS[] = {
|
||||
"/usr/share/tessdata/",
|
||||
"/usr/share/tesseract-ocr/tessdata/",
|
||||
"./",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
scan_args_t *scan_args_create() {
|
||||
scan_args_t *args = calloc(sizeof(scan_args_t), 1);
|
||||
@@ -136,13 +143,23 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
||||
|
||||
if (args->tesseract_lang != NULL) {
|
||||
TessBaseAPI *api = TessBaseAPICreate();
|
||||
ret = TessBaseAPIInit3(api, TESS_DATAPATH, args->tesseract_lang);
|
||||
|
||||
char filename[128];
|
||||
sprintf(filename, "%s.traineddata", args->tesseract_lang);
|
||||
const char * path = find_file_in_paths(TESS_DATAPATHS, filename);
|
||||
if (path == NULL) {
|
||||
LOG_FATAL("cli.c", "Could not find tesseract language file!");
|
||||
}
|
||||
|
||||
ret = TessBaseAPIInit3(api, path, args->tesseract_lang);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "Could not initialize tesseract with lang '%s'\n", args->tesseract_lang);
|
||||
return 1;
|
||||
}
|
||||
TessBaseAPIEnd(api);
|
||||
TessBaseAPIDelete(api);
|
||||
|
||||
args->tesseract_path = path;
|
||||
}
|
||||
|
||||
LOG_DEBUGF("cli.c", "arg quality=%f", args->quality)
|
||||
@@ -156,7 +173,8 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
||||
LOG_DEBUGF("cli.c", "arg depth=%d", args->depth)
|
||||
LOG_DEBUGF("cli.c", "arg path=%s", args->path)
|
||||
LOG_DEBUGF("cli.c", "arg archive=%s", args->archive)
|
||||
LOG_DEBUGF("cli.c", "arg ocr=%s", args->tesseract_lang)
|
||||
LOG_DEBUGF("cli.c", "arg tesseract_lang=%s", args->tesseract_lang)
|
||||
LOG_DEBUGF("cli.c", "arg tesseract_path=%s", args->tesseract_path)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ typedef struct scan_args {
|
||||
char *archive;
|
||||
archive_mode_t archive_mode;
|
||||
char *tesseract_lang;
|
||||
const char *tesseract_path;
|
||||
} scan_args_t;
|
||||
|
||||
scan_args_t *scan_args_create();
|
||||
|
||||
@@ -28,6 +28,7 @@ struct {
|
||||
|
||||
pthread_mutex_t mupdf_mu;
|
||||
char * tesseract_lang;
|
||||
char * tesseract_path;
|
||||
} ScanCtx;
|
||||
|
||||
struct {
|
||||
|
||||
@@ -136,7 +136,7 @@ void elastic_flush() {
|
||||
LOG_FATALF("elastic.c", "Could not connect to %s, make sure that elasticsearch is running!\n", IndexCtx.es_url)
|
||||
}
|
||||
|
||||
LOG_INFOF("elastic.c", "Indexed %3d documents (%zukB) <%d>", count, buf_cur / 1024, r->status_code);
|
||||
LOG_INFOF("elastic.c", "Indexed %d documents (%zukB) <%d>", count, buf_cur / 1024, r->status_code);
|
||||
|
||||
cJSON *ret_json = cJSON_Parse(r->body);
|
||||
if (cJSON_GetObjectItem(ret_json, "errors")->valueint != 0) {
|
||||
@@ -274,3 +274,28 @@ cJSON *elastic_get_document(const char *uuid_str) {
|
||||
free_response(r);
|
||||
return json;
|
||||
}
|
||||
|
||||
char *elastic_get_status() {
|
||||
char url[4096];
|
||||
snprintf(url, 4096,
|
||||
"%s/_cluster/state/metadata/sist2?filter_path=metadata.indices.*.state", WebCtx.es_url);
|
||||
|
||||
response_t *r = web_get(url);
|
||||
cJSON *json = NULL;
|
||||
char *status = malloc(128 * sizeof(char));
|
||||
status[0] = '\0';
|
||||
|
||||
if (r->status_code == 200) {
|
||||
json = cJSON_Parse(r->body);
|
||||
const cJSON *metadata = cJSON_GetObjectItem(json, "metadata");
|
||||
if (metadata != NULL) {
|
||||
const cJSON *indices = cJSON_GetObjectItem(metadata, "indices");
|
||||
const cJSON *sist2 = cJSON_GetObjectItem(indices, "sist2");
|
||||
const cJSON *state = cJSON_GetObjectItem(sist2, "state");
|
||||
strcpy(status, state->valuestring);
|
||||
}
|
||||
}
|
||||
free_response(r);
|
||||
cJSON_Delete(json);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -30,4 +30,6 @@ void elastic_init(int force_reset);
|
||||
|
||||
cJSON *elastic_get_document(const char *uuid_str);
|
||||
|
||||
char *elastic_get_status();
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -118,6 +118,22 @@ char *get_meta_key_text(enum metakey meta_key) {
|
||||
return "font_name";
|
||||
case MetaParent:
|
||||
return "parent";
|
||||
case MetaExifMake:
|
||||
return "exif_make";
|
||||
case MetaExifSoftware:
|
||||
return "exif_software";
|
||||
case MetaExifExposureTime:
|
||||
return "exif_exposure_time";
|
||||
case MetaExifFNumber:
|
||||
return "exif_fnumber";
|
||||
case MetaExifFocalLength:
|
||||
return "exif_focal_length";
|
||||
case MetaExifUserComment:
|
||||
return "exif_user_comment";
|
||||
case MetaExifIsoSpeedRatings:
|
||||
return "exif_iso_speed_ratings";
|
||||
case MetaExifModel:
|
||||
return "exif_model";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@@ -255,6 +271,14 @@ void read_index_bin(const char *path, const char *index_id, index_func func) {
|
||||
case MetaGenre:
|
||||
case MetaFontName:
|
||||
case MetaParent:
|
||||
case MetaExifMake:
|
||||
case MetaExifSoftware:
|
||||
case MetaExifExposureTime:
|
||||
case MetaExifFNumber:
|
||||
case MetaExifFocalLength:
|
||||
case MetaExifUserComment:
|
||||
case MetaExifIsoSpeedRatings:
|
||||
case MetaExifModel:
|
||||
case MetaTitle: {
|
||||
buf.cur = 0;
|
||||
while ((c = getc(file)) != 0) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
||||
|
||||
|
||||
static const char *const Version = "1.2.1";
|
||||
static const char *const Version = "1.2.5";
|
||||
static const char *const usage[] = {
|
||||
"sist2 scan [OPTION]... PATH",
|
||||
"sist2 index [OPTION]... INDEX",
|
||||
@@ -51,6 +51,7 @@ void sist2_scan(scan_args_t *args) {
|
||||
strncpy(ScanCtx.index.desc.root, args->path, sizeof(ScanCtx.index.desc.root));
|
||||
ScanCtx.index.desc.root_len = (short) strlen(ScanCtx.index.desc.root);
|
||||
ScanCtx.tesseract_lang = args->tesseract_lang;
|
||||
ScanCtx.tesseract_path = args->tesseract_path;
|
||||
|
||||
init_dir(ScanCtx.index.path);
|
||||
|
||||
|
||||
@@ -55,7 +55,14 @@ __always_inline
|
||||
void read_part(opcContainer *c, dyn_buffer_t *buf, opcPart part, document_t *doc) {
|
||||
|
||||
mceTextReader_t reader;
|
||||
int ret = opcXmlReaderOpen(c, &reader, part, NULL, "UTF-8", 0);
|
||||
int options;
|
||||
if (LogCtx.very_verbose) {
|
||||
options = XML_PARSE_NONET;
|
||||
} else {
|
||||
options = XML_PARSE_NOWARNING | XML_PARSE_NOERROR | XML_PARSE_NONET;
|
||||
}
|
||||
|
||||
int ret = opcXmlReaderOpen(c, &reader, part, NULL, "UTF-8", options);
|
||||
|
||||
if (ret != OPC_ERROR_NONE) {
|
||||
LOG_ERRORF(doc->filepath, "(doc.c) opcXmlReaderOpen() returned error code %d", ret);
|
||||
|
||||
@@ -193,6 +193,22 @@ append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *doc,
|
||||
APPEND_TAG_META(doc, tag, MetaArtist)
|
||||
} else if (strcmp(tag->key, "ImageDescription") == 0) {
|
||||
APPEND_TAG_META(doc, tag, MetaContent)
|
||||
} else if (strcmp(tag->key, "Make") == 0) {
|
||||
APPEND_TAG_META(doc, tag, MetaExifMake)
|
||||
} else if (strcmp(tag->key, "Model") == 0) {
|
||||
APPEND_TAG_META(doc, tag, MetaExifModel)
|
||||
} else if (strcmp(tag->key, "Software") == 0) {
|
||||
APPEND_TAG_META(doc, tag, MetaExifSoftware)
|
||||
} else if (strcmp(tag->key, "FNumber") == 0) {
|
||||
APPEND_TAG_META(doc, tag, MetaExifFNumber)
|
||||
} else if (strcmp(tag->key, "FocalLength") == 0) {
|
||||
APPEND_TAG_META(doc, tag, MetaExifFocalLength)
|
||||
} else if (strcmp(tag->key, "UserComment") == 0) {
|
||||
APPEND_TAG_META(doc, tag, MetaExifUserComment)
|
||||
} else if (strcmp(tag->key, "ISOSpeedRatings") == 0) {
|
||||
APPEND_TAG_META(doc, tag, MetaExifIsoSpeedRatings)
|
||||
} else if (strcmp(tag->key, "ExposureTime") == 0) {
|
||||
APPEND_TAG_META(doc, tag, MetaExifExposureTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,8 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
||||
fz_drop_pixmap(ctx, pixmap);
|
||||
|
||||
if (err != 0) {
|
||||
LOG_WARNINGF(doc->filepath, "fz_new_buffer_from_pixmap_as_png() returned error code [%d] %s", err, ctx->error.message)
|
||||
LOG_WARNINGF(doc->filepath, "fz_new_buffer_from_pixmap_as_png() returned error code [%d] %s", err,
|
||||
ctx->error.message)
|
||||
fz_drop_page(ctx, cover);
|
||||
return NULL;
|
||||
}
|
||||
@@ -129,8 +130,8 @@ int read_stext_block(fz_stext_block *block, text_buffer_t *tex) {
|
||||
|
||||
|
||||
void fill_image(fz_context *ctx, UNUSED(fz_device *dev),
|
||||
fz_image *img, UNUSED(fz_matrix ctm), UNUSED(float alpha),
|
||||
UNUSED(fz_color_params color_params)) {
|
||||
fz_image *img, UNUSED(fz_matrix ctm), UNUSED(float alpha),
|
||||
UNUSED(fz_color_params color_params)) {
|
||||
|
||||
int l2factor = 0;
|
||||
|
||||
@@ -140,7 +141,7 @@ void fill_image(fz_context *ctx, UNUSED(fz_device *dev),
|
||||
|
||||
if (pix->h > MIN_OCR_SIZE && img->h > MIN_OCR_SIZE && img->xres != 0) {
|
||||
TessBaseAPI *api = TessBaseAPICreate();
|
||||
TessBaseAPIInit3(api, TESS_DATAPATH, ScanCtx.tesseract_lang);
|
||||
TessBaseAPIInit3(api, ScanCtx.tesseract_path, ScanCtx.tesseract_lang);
|
||||
|
||||
TessBaseAPISetImage(api, pix->samples, pix->w, pix->h, pix->n, pix->stride);
|
||||
TessBaseAPISetSourceResolution(api, pix->xres);
|
||||
@@ -156,8 +157,8 @@ void fill_image(fz_context *ctx, UNUSED(fz_device *dev),
|
||||
|
||||
TessBaseAPIEnd(api);
|
||||
TessBaseAPIDelete(api);
|
||||
fz_drop_pixmap(ctx, pix);
|
||||
}
|
||||
fz_drop_pixmap(ctx, pix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define SIST2_PDF_H
|
||||
|
||||
#include "src/sist.h"
|
||||
#include <tesseract/capi.h>
|
||||
|
||||
|
||||
void parse_pdf(void *buf, size_t buf_len, document_t *doc);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#define UUID_STR_LEN 37
|
||||
#define UNUSED(x) __attribute__((__unused__)) x
|
||||
#define TESS_DATAPATH "/usr/share/tessdata/"
|
||||
|
||||
#include <glib-2.0/glib.h>
|
||||
#include <unistd.h>
|
||||
@@ -34,6 +33,8 @@
|
||||
#include <archive_entry.h>
|
||||
#include <opc/opc.h>
|
||||
#include <libxml/xmlstring.h>
|
||||
#define BOOL int
|
||||
#include <tesseract/capi.h>
|
||||
|
||||
#include <onion/onion.h>
|
||||
#include <onion/handler.h>
|
||||
|
||||
15
src/types.h
15
src/types.h
@@ -2,9 +2,9 @@
|
||||
#define SIST2_TYPES_H
|
||||
|
||||
|
||||
#define META_INT_MASK 0xF0
|
||||
#define META_STR_MASK 0xE0
|
||||
#define META_LONG_MASK 0xD0
|
||||
#define META_INT_MASK 0x80
|
||||
#define META_STR_MASK 0x40
|
||||
#define META_LONG_MASK 0x20
|
||||
#define IS_META_INT(key) (key & META_INT_MASK) == META_INT_MASK
|
||||
#define IS_META_LONG(key) (key & META_LONG_MASK) == META_LONG_MASK
|
||||
#define IS_META_STR(meta) (meta->key & META_STR_MASK) == META_STR_MASK
|
||||
@@ -31,6 +31,15 @@ enum metakey {
|
||||
MetaTitle = 12 | META_STR_MASK,
|
||||
MetaFontName = 13 | META_STR_MASK,
|
||||
MetaParent = 14 | META_STR_MASK,
|
||||
MetaExifMake = 15 | META_STR_MASK,
|
||||
MetaExifSoftware = 16 | META_STR_MASK,
|
||||
MetaExifExposureTime = 17 | META_STR_MASK,
|
||||
MetaExifFNumber = 18 | META_STR_MASK,
|
||||
MetaExifFocalLength = 19 | META_STR_MASK,
|
||||
MetaExifUserComment = 20 | META_STR_MASK,
|
||||
MetaExifModel = 21 | META_STR_MASK,
|
||||
MetaExifIsoSpeedRatings = 22 | META_STR_MASK,
|
||||
//Note to self: this will break after 31 entries
|
||||
};
|
||||
|
||||
#define INDEX_TYPE_BIN "binary"
|
||||
|
||||
36
src/util.c
36
src/util.c
@@ -1,4 +1,5 @@
|
||||
#include "util.h"
|
||||
#include "src/ctx.h"
|
||||
|
||||
dyn_buffer_t dyn_buffer_create() {
|
||||
dyn_buffer_t buf;
|
||||
@@ -90,7 +91,11 @@ text_buffer_t text_buffer_create(int max_size) {
|
||||
}
|
||||
|
||||
void text_buffer_terminate_string(text_buffer_t *buf) {
|
||||
dyn_buffer_write_char(&buf->dyn_buffer, '\0');
|
||||
if (*(buf->dyn_buffer.buf + buf->dyn_buffer.cur - 1) == ' ') {
|
||||
*(buf->dyn_buffer.buf + buf->dyn_buffer.cur - 1) = '\0';
|
||||
} else {
|
||||
dyn_buffer_write_char(&buf->dyn_buffer, '\0');
|
||||
}
|
||||
}
|
||||
|
||||
__always_inline
|
||||
@@ -171,8 +176,8 @@ int text_buffer_append_string0(text_buffer_t *buf, char *str) {
|
||||
|
||||
int text_buffer_append_char(text_buffer_t *buf, int c) {
|
||||
|
||||
if (SHOULD_IGNORE_CHAR(c)) {
|
||||
if (!buf->last_char_was_whitespace) {
|
||||
if (SHOULD_IGNORE_CHAR(c) || c == ' ') {
|
||||
if (!buf->last_char_was_whitespace && buf->dyn_buffer.cur != 0) {
|
||||
dyn_buffer_write_char(&buf->dyn_buffer, ' ');
|
||||
buf->last_char_was_whitespace = TRUE;
|
||||
|
||||
@@ -317,4 +322,29 @@ GHashTable *incremental_get_table() {
|
||||
return file_table;
|
||||
}
|
||||
|
||||
const char *find_file_in_paths(const char *paths[], const char *filename) {
|
||||
|
||||
for (int i = 0; paths[i] != NULL; i++) {
|
||||
|
||||
char *apath = abspath(paths[i]);
|
||||
if (apath == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, sizeof(path), "%s%s", apath, filename);
|
||||
|
||||
LOG_DEBUGF("util.c", "Looking for '%s' in folder '%s'", filename, apath)
|
||||
free(apath);
|
||||
|
||||
struct stat info;
|
||||
int ret = stat(path, &info);
|
||||
if (ret != -1) {
|
||||
return paths[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -74,5 +74,6 @@ int incremental_get(GHashTable *table, unsigned long inode_no);
|
||||
|
||||
int incremental_mark_file_for_copy(GHashTable *table, unsigned long inode_no);
|
||||
|
||||
const char *find_file_in_paths(const char **paths, const char *filename);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -110,7 +110,7 @@ int thumbnail(void *p, onion_request *req, onion_response *res) {
|
||||
int written = onion_response_write(res, data, data_len);
|
||||
onion_response_flush(res);
|
||||
if (written != data_len || data_len == 0) {
|
||||
printf("Couldn't write thumb\n");
|
||||
LOG_DEBUG("serve.c", "Couldn't write thumbnail");
|
||||
}
|
||||
free(data);
|
||||
|
||||
@@ -214,7 +214,7 @@ int chunked_response_file(const char *filename, const char *mime,
|
||||
return OCS_PROCESSED;
|
||||
}
|
||||
|
||||
int search(void *p, onion_request *req, onion_response *res) {
|
||||
int search(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||
|
||||
int flags = onion_request_get_flags(req);
|
||||
if ((flags & OR_METHODS) != OR_POST) {
|
||||
@@ -254,7 +254,7 @@ int search(void *p, onion_request *req, onion_response *res) {
|
||||
return OCS_PROCESSED;
|
||||
}
|
||||
|
||||
int scroll(void *p, onion_request *req, onion_response *res) {
|
||||
int scroll(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||
|
||||
int flags = onion_request_get_flags(req);
|
||||
if ((flags & OR_METHODS) != OR_GET) {
|
||||
@@ -327,7 +327,7 @@ int serve_file_from_disk(cJSON *json, index_t *idx, onion_request *req, onion_re
|
||||
return chunked_response_file(full_path, mime, 1, req, res);
|
||||
}
|
||||
|
||||
int index_info(void *p, onion_request *req, onion_response *res) {
|
||||
int index_info(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||
cJSON *json = cJSON_CreateObject();
|
||||
cJSON *arr = cJSON_AddArrayToObject(json, "indices");
|
||||
|
||||
@@ -353,14 +353,47 @@ int index_info(void *p, onion_request *req, onion_response *res) {
|
||||
return OCS_PROCESSED;
|
||||
}
|
||||
|
||||
int file(void *p, onion_request *req, onion_response *res) {
|
||||
|
||||
int document_info(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||
|
||||
const char *arg_uuid = onion_request_get_query(req, "1");
|
||||
if (arg_uuid == NULL) {
|
||||
return OCS_PROCESSED;
|
||||
}
|
||||
|
||||
char *next = arg_uuid;
|
||||
cJSON *doc = elastic_get_document(arg_uuid);
|
||||
cJSON *source = cJSON_GetObjectItem(doc, "_source");
|
||||
|
||||
cJSON *index_id = cJSON_GetObjectItem(source, "index");
|
||||
if (index_id == NULL) {
|
||||
cJSON_Delete(doc);
|
||||
return OCS_NOT_PROCESSED;
|
||||
}
|
||||
|
||||
index_t *idx = get_index_by_id(index_id->valuestring);
|
||||
if (idx == NULL) {
|
||||
cJSON_Delete(doc);
|
||||
return OCS_NOT_PROCESSED;
|
||||
}
|
||||
|
||||
onion_response_set_header(res, "Content-Type", "application/json");
|
||||
|
||||
char *json_str = cJSON_PrintUnformatted(source);
|
||||
onion_response_write0(res, json_str);
|
||||
free(json_str);
|
||||
cJSON_Delete(doc);
|
||||
|
||||
return OCS_PROCESSED;
|
||||
}
|
||||
|
||||
int file(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||
|
||||
const char *arg_uuid = onion_request_get_query(req, "1");
|
||||
if (arg_uuid == NULL) {
|
||||
return OCS_PROCESSED;
|
||||
}
|
||||
|
||||
const char *next = arg_uuid;
|
||||
cJSON *doc = NULL;
|
||||
cJSON *index_id = NULL;
|
||||
cJSON *source = NULL;
|
||||
@@ -398,6 +431,23 @@ int file(void *p, onion_request *req, onion_response *res) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int status(UNUSED(void *p), UNUSED(onion_request *req), onion_response *res) {
|
||||
set_default_headers(res);
|
||||
|
||||
onion_response_set_header(res, "Content-Type", "application/x-empty");
|
||||
|
||||
char *status = elastic_get_status();
|
||||
if (strcmp(status, "open") == 0) {
|
||||
onion_response_set_code(res, 204);
|
||||
} else {
|
||||
onion_response_set_code(res, 500);
|
||||
}
|
||||
|
||||
free(status);
|
||||
|
||||
return OCS_PROCESSED;
|
||||
}
|
||||
|
||||
void serve(const char *hostname, const char *port) {
|
||||
onion *o = onion_new(O_POOL);
|
||||
onion_set_timeout(o, 3500);
|
||||
@@ -417,6 +467,7 @@ void serve(const char *hostname, const char *port) {
|
||||
|
||||
onion_url_add(urls, "es", search);
|
||||
onion_url_add(urls, "scroll", scroll);
|
||||
onion_url_add(urls, "status", status);
|
||||
onion_url_add(
|
||||
urls,
|
||||
"^t/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})/"
|
||||
@@ -424,6 +475,7 @@ void serve(const char *hostname, const char *port) {
|
||||
thumbnail
|
||||
);
|
||||
onion_url_add(urls, "^f/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$", file);
|
||||
onion_url_add(urls, "^d/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$", document_info);
|
||||
onion_url_add(urls, "i", index_info);
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2,6 +2,26 @@
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.info-icon {
|
||||
width: 1rem;
|
||||
margin-right: 0.2rem;
|
||||
cursor: pointer;
|
||||
color: #757575;
|
||||
line-height: 1rem;
|
||||
height: 1.1rem;
|
||||
}
|
||||
|
||||
.info-icon:hover {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
max-width: calc(100% - 2rem);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
|
||||
.path-row {
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
@@ -32,7 +52,7 @@ body {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.card {
|
||||
.card, .modal-content {
|
||||
margin-top: 1em;
|
||||
background: #212121;
|
||||
color: #e0e0e0;
|
||||
@@ -40,6 +60,27 @@ body {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.table {
|
||||
color: #e0e0e0;
|
||||
}
|
||||
|
||||
.table td, .table th {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.table thead th {
|
||||
border-bottom: 1px solid #646464;
|
||||
}
|
||||
|
||||
.modal-header .close {
|
||||
color: #e0e0e0;
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
border-bottom: 1px solid #646464;
|
||||
}
|
||||
|
||||
.sub-document {
|
||||
background: #37474F !important;
|
||||
}
|
||||
@@ -134,6 +175,8 @@ body {
|
||||
|
||||
.file-title {
|
||||
width: 100%;
|
||||
line-height: 1rem;
|
||||
height: 1.1rem;
|
||||
font-size: 10pt;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
@@ -2,6 +2,25 @@
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.info-icon {
|
||||
width: 1rem;
|
||||
margin-right: 0.2rem;
|
||||
cursor: pointer;
|
||||
color: #757575;
|
||||
line-height: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
|
||||
.info-icon:hover {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
max-width: calc(100% - 2rem);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.path-row {
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
@@ -100,6 +119,8 @@ body {
|
||||
|
||||
.file-title {
|
||||
width: 100%;
|
||||
line-height: 1rem;
|
||||
height: 1.1rem;
|
||||
font-size: 10pt;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
@@ -153,11 +153,44 @@ function getTags(hit, mimeCategory) {
|
||||
return tags
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param hit
|
||||
* @returns {Element}
|
||||
*/
|
||||
function infoButtonCb(hit) {
|
||||
return () => {
|
||||
getDocumentInfo(hit["_id"]).then(doc => {
|
||||
$("#modal-title").text(doc["name"] + (doc["extension"] ? "." + doc["extension"] : ""));
|
||||
|
||||
const tbody = $("<tbody>");
|
||||
$("#modal-body").empty()
|
||||
.append($("<table class='table table-sm'>")
|
||||
.append($("<thead>")
|
||||
.append($("<tr>")
|
||||
.append($("<th>").text("Field"))
|
||||
.append($("<th>").text("Value"))
|
||||
)
|
||||
)
|
||||
.append(tbody)
|
||||
);
|
||||
|
||||
const displayFields = new Set([
|
||||
"mime", "size", "mtime", "path", "title", "width", "height", "duration", "audioc", "videoc",
|
||||
"bitrate", "artist", "album", "album_artist", "genre", "title", "font_name", "tag"
|
||||
]);
|
||||
Object.keys(doc)
|
||||
.filter(key => key.startsWith("_keyword.") || key.startsWith("_text.") || displayFields.has(key))
|
||||
.forEach(key => {
|
||||
tbody.append($("<tr>")
|
||||
.append($("<td>").text(key))
|
||||
.append($("<td>").text(doc[key]))
|
||||
);
|
||||
});
|
||||
if (doc.hasOwnProperty("content") && doc["content"]) {
|
||||
$("#modal-body").append($("<div class='content-div'>").text(doc["content"]))
|
||||
}
|
||||
|
||||
$("#modal").modal();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createDocCard(hit) {
|
||||
let docCard = document.createElement("div");
|
||||
docCard.setAttribute("class", "card");
|
||||
@@ -172,6 +205,7 @@ function createDocCard(hit) {
|
||||
let link = document.createElement("a");
|
||||
link.setAttribute("href", "f/" + hit["_id"]);
|
||||
link.setAttribute("target", "_blank");
|
||||
link.style.maxWidth = "calc(100% - 1.2rem)";
|
||||
link.appendChild(title);
|
||||
|
||||
if (hit["_source"].hasOwnProperty("parent")) {
|
||||
@@ -271,7 +305,15 @@ function createDocCard(hit) {
|
||||
sizeTag.setAttribute("class", "text-muted");
|
||||
tagContainer.appendChild(sizeTag);
|
||||
|
||||
docCardBody.appendChild(link);
|
||||
const titleWrapper = document.createElement("div");
|
||||
titleWrapper.style.display = "flex";
|
||||
|
||||
const infoButton = makeInfoButton(hit);
|
||||
|
||||
titleWrapper.appendChild(infoButton);
|
||||
titleWrapper.appendChild(link);
|
||||
|
||||
docCardBody.appendChild(titleWrapper);
|
||||
docCard.appendChild(docCardBody);
|
||||
|
||||
docCardBody.appendChild(tagContainer);
|
||||
@@ -352,6 +394,14 @@ function makeThumbnail(mimeCategory, hit, imgWrapper, small) {
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
function makeInfoButton(hit) {
|
||||
const infoButton = document.createElement("span");
|
||||
infoButton.appendChild(document.createTextNode("🛈"));
|
||||
infoButton.setAttribute("class", "info-icon");
|
||||
infoButton.addEventListener("click", infoButtonCb(hit));
|
||||
return infoButton;
|
||||
}
|
||||
|
||||
function createDocLine(hit) {
|
||||
|
||||
const mime = hit["_source"]["mime"];
|
||||
@@ -372,6 +422,8 @@ function createDocLine(hit) {
|
||||
isSubDocument = true;
|
||||
}
|
||||
|
||||
const infoButton = makeInfoButton(hit);
|
||||
|
||||
const title = makeTitle(hit);
|
||||
|
||||
let link = document.createElement("a");
|
||||
@@ -380,8 +432,13 @@ function createDocLine(hit) {
|
||||
link.appendChild(title);
|
||||
|
||||
const titleDiv = document.createElement("div");
|
||||
titleDiv.setAttribute("class", "file-title");
|
||||
titleDiv.appendChild(link);
|
||||
|
||||
const titleWrapper = document.createElement("div");
|
||||
titleWrapper.style.display = "flex";
|
||||
titleWrapper.appendChild(infoButton);
|
||||
titleWrapper.appendChild(link);
|
||||
|
||||
titleDiv.appendChild(titleWrapper);
|
||||
|
||||
line.appendChild(media);
|
||||
|
||||
|
||||
@@ -81,6 +81,13 @@ $.jsonPost("i").then(resp => {
|
||||
});
|
||||
});
|
||||
|
||||
function getDocumentInfo(id) {
|
||||
return $.getJSON("d/" + id).fail(e => {
|
||||
console.log(e);
|
||||
showEsError();
|
||||
})
|
||||
}
|
||||
|
||||
function handleTreeClick(tree) {
|
||||
return (event, node, handler) => {
|
||||
event.preventTreeDefault();
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<nav class="navbar navbar-expand-lg">
|
||||
<a class="navbar-brand" href="/">sist2</a>
|
||||
<span class="badge badge-pill version">v1.2.1</span>
|
||||
<span class="badge badge-pill version">v1.2.5</span>
|
||||
<span class="tagline">Lightning-fast file system indexer and search tool </span>
|
||||
<a style="margin-left: auto" id="theme" class="btn" title="Toggle theme" href="/">Theme</a>
|
||||
</nav>
|
||||
@@ -65,6 +65,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal" id="modal" tabindex="-1" role="dialog" aria-labelledby="modal-title" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="modal-title"></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body" id="modal-body"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="searchResults"></div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user