mirror of
https://github.com/simon987/sist2.git
synced 2025-12-12 15:08:53 +00:00
Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a8505cb8c1 | |||
| ae8652d86e | |||
| 849beb09d8 | |||
| e1aaaee617 | |||
| c02b940945 | |||
| 2934ddb07f | |||
| 7f6f3c02fa | |||
| 7f98d5a682 | |||
| 7eb9c5d7d5 | |||
| 184439aa38 | |||
| 1ce8b298a1 | |||
| 75f99025d9 | |||
| ebe852bd5a | |||
| 402b103c49 | |||
| e9b6e1cdc2 | |||
| ed1ce8ab5e | |||
| d1fa4febc4 | |||
| 048c55df7b | |||
| f77bc6a025 | |||
| efdde2734e | |||
| 66658fa8f7 | |||
| df41c251e4 | |||
| 3282ab56ba | |||
| 8300838d30 | |||
| c9870a6d3d | |||
| a143cc4fcf | |||
| 9ef1f3781d | |||
| bbee8aa721 | |||
| d22f83c797 | |||
| 50615486a4 | |||
| ca79e4f797 | |||
| 6a9fd08a80 | |||
| cab890dc9b | |||
| b3c4faf2df | |||
| 353937171a | |||
| c80002bea4 | |||
| 56adee9d81 | |||
| d6493d6d5f | |||
| 0967e9676d | |||
| 487e998ea0 | |||
| 919f45c79c | |||
| d42129cfcb | |||
| 754983e34a | |||
| 7c8a3e2f9d | |||
| 3bb24b4453 |
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -37,3 +37,9 @@
|
|||||||
[submodule "lib/leptonica"]
|
[submodule "lib/leptonica"]
|
||||||
path = lib/leptonica
|
path = lib/leptonica
|
||||||
url = https://github.com/danbloomberg/leptonica
|
url = https://github.com/danbloomberg/leptonica
|
||||||
|
[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)
|
find_package(PkgConfig REQUIRED)
|
||||||
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig/")
|
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig/")
|
||||||
|
|
||||||
#find_package(OpenSSL REQUIRED)
|
|
||||||
find_package(Freetype REQUIRED)
|
find_package(Freetype REQUIRED)
|
||||||
|
|
||||||
pkg_check_modules(GLIB REQUIRED glib-2.0)
|
pkg_check_modules(GLIB REQUIRED glib-2.0)
|
||||||
@@ -84,7 +83,8 @@ target_link_directories(
|
|||||||
target_compile_options(sist2
|
target_compile_options(sist2
|
||||||
PRIVATE
|
PRIVATE
|
||||||
-Ofast
|
-Ofast
|
||||||
# -march=native
|
# -march=native
|
||||||
|
-fPIC
|
||||||
-fno-stack-protector
|
-fno-stack-protector
|
||||||
-fomit-frame-pointer
|
-fomit-frame-pointer
|
||||||
)
|
)
|
||||||
@@ -111,7 +111,7 @@ TARGET_LINK_LIBRARIES(
|
|||||||
${PROJECT_SOURCE_DIR}/lib/libonion_static.a
|
${PROJECT_SOURCE_DIR}/lib/libonion_static.a
|
||||||
|
|
||||||
pthread
|
pthread
|
||||||
curl
|
|
||||||
m
|
m
|
||||||
bz2
|
bz2
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmagic.a
|
${PROJECT_SOURCE_DIR}/lib/libmagic.a
|
||||||
@@ -127,9 +127,15 @@ TARGET_LINK_LIBRARIES(
|
|||||||
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libtesseract.a
|
${PROJECT_SOURCE_DIR}/lib/libtesseract.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/liblept.a
|
${PROJECT_SOURCE_DIR}/lib/liblept.a
|
||||||
png
|
${PROJECT_SOURCE_DIR}/lib/libtiff.a
|
||||||
tiff
|
${PROJECT_SOURCE_DIR}/lib/libpng16.a
|
||||||
stdc++
|
stdc++
|
||||||
|
|
||||||
|
# curl
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libcurl.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libcrypto.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libssl.a
|
||||||
|
dl
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
|
|||||||
@@ -16,4 +16,7 @@ RUN mkdir -p /usr/share/tessdata && \
|
|||||||
|
|
||||||
ADD sist2 /root/sist2
|
ADD sist2 /root/sist2
|
||||||
|
|
||||||
|
ENV LANG C.UTF-8
|
||||||
|
ENV LC_ALL C.UTF-8
|
||||||
|
|
||||||
ENTRYPOINT ["/root/sist2"]
|
ENTRYPOINT ["/root/sist2"]
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ strip sist2
|
|||||||
version=$(./sist2 --version)
|
version=$(./sist2 --version)
|
||||||
|
|
||||||
echo "Version ${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:${version}
|
||||||
docker push simon987/sist2:latest
|
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. Have an [Elasticsearch](https://www.elastic.co/downloads/elasticsearch) instance running
|
||||||
1.
|
1.
|
||||||
1. Download the [latest sist2 release](https://github.com/simon987/sist2/releases) *
|
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`
|
1. *(or)* `docker pull simon987/sist2:latest`
|
||||||
|
|
||||||
|
|
||||||
@@ -39,6 +39,9 @@ sist2 (Simple incremental search tool)
|
|||||||
|
|
||||||
## Example usage
|
## Example usage
|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
See help page `sist2 --help` for more details.
|
See help page `sist2 --help` for more details.
|
||||||
|
|
||||||
**Scan a directory**
|
**Scan a directory**
|
||||||
@@ -92,7 +95,7 @@ File type | Library | Content | Thumbnail | Metadata
|
|||||||
pdf,xps,cbz,fb2,epub | MuPDF | text+ocr | yes, `png` | title |
|
pdf,xps,cbz,fb2,epub | MuPDF | text+ocr | yes, `png` | title |
|
||||||
`audio/*` | ffmpeg | - | yes, `jpeg` | ID3 tags |
|
`audio/*` | ffmpeg | - | yes, `jpeg` | ID3 tags |
|
||||||
`video/*` | ffmpeg | - | yes, `jpeg` | title, comment, artist |
|
`video/*` | ffmpeg | - | yes, `jpeg` | title, comment, artist |
|
||||||
`image/*` | ffmpeg | - | yes, `jpeg` | `EXIF:Artist`, `EXIF:ImageDescription` |
|
`image/*` | ffmpeg | - | yes, `jpeg` | [Common EXIF tags](https://github.com/simon987/sist2/blob/efdde2734eca9b14a54f84568863b7ffd59bdba3/src/parsing/media.c#L190) |
|
||||||
ttf,ttc,cff,woff,fnt,otf | Freetype2 | - | yes, `bmp` | Name & style |
|
ttf,ttc,cff,woff,fnt,otf | Freetype2 | - | yes, `bmp` | Name & style |
|
||||||
`text/plain` | *(none)* | yes | no | - |
|
`text/plain` | *(none)* | yes | no | - |
|
||||||
tar, zip, rar, 7z, ar ... | Libarchive | yes\* | - | no |
|
tar, zip, rar, 7z, ar ... | Libarchive | yes\* | - | no |
|
||||||
@@ -143,7 +146,7 @@ binaries.
|
|||||||
apt install git cmake pkg-config libglib2.0-dev \
|
apt install git cmake pkg-config libglib2.0-dev \
|
||||||
libssl-dev uuid-dev python3 libmagic-dev libfreetype6-dev \
|
libssl-dev uuid-dev python3 libmagic-dev libfreetype6-dev \
|
||||||
libcurl-dev libbz2-dev yasm libharfbuzz-dev ragel \
|
libcurl-dev libbz2-dev yasm libharfbuzz-dev ragel \
|
||||||
libarchive-dev libtiff5 libpng16-16
|
libarchive-dev libtiff5 libpng16-16 libpango1.0-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Build
|
2. Build
|
||||||
|
|||||||
@@ -5,4 +5,3 @@
|
|||||||
cmake .
|
cmake .
|
||||||
make
|
make
|
||||||
strip sist2
|
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
1
lib/libtiff
Submodule
1
lib/libtiff
Submodule
Submodule lib/libtiff added at 3db0ff91bc
2
mime.csv
2
mime.csv
@@ -320,7 +320,7 @@ video/x-dv, dif|dv
|
|||||||
video/x-fli, fli
|
video/x-fli, fli
|
||||||
video/x-isvideo, isu
|
video/x-isvideo, isu
|
||||||
video/x-motion-jpeg, mjpg
|
video/x-motion-jpeg, mjpg
|
||||||
video/x-ms-asf, asf|asx
|
video/x-ms-asf, asf|asx|wmv
|
||||||
video/x-qtc, qtc
|
video/x-qtc, qtc
|
||||||
video/x-sgi-movie, movie|mv
|
video/x-sgi-movie, movie|mv
|
||||||
application/x-7z-compressed, 7z
|
application/x-7z-compressed, 7z
|
||||||
|
|||||||
|
@@ -1,5 +1,9 @@
|
|||||||
{
|
{
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"_tie": {
|
||||||
|
"type": "keyword",
|
||||||
|
"doc_values": true
|
||||||
|
},
|
||||||
"path": {
|
"path": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"analyzer": "path_analyzer",
|
"analyzer": "path_analyzer",
|
||||||
@@ -7,25 +11,30 @@
|
|||||||
},
|
},
|
||||||
"suggest-path": {
|
"suggest-path": {
|
||||||
"type": "completion",
|
"type": "completion",
|
||||||
"analyzer": "keyword"
|
"analyzer": "case_insensitive_kw_analyzer"
|
||||||
},
|
},
|
||||||
"mime": {
|
"mime": {
|
||||||
"type": "keyword"
|
"type": "keyword"
|
||||||
},
|
},
|
||||||
"videoc": {
|
"videoc": {
|
||||||
"type": "keyword"
|
"type": "keyword",
|
||||||
|
"index": false
|
||||||
},
|
},
|
||||||
"audioc": {
|
"audioc": {
|
||||||
"type": "keyword"
|
"type": "keyword",
|
||||||
|
"index": false
|
||||||
},
|
},
|
||||||
"duration": {
|
"duration": {
|
||||||
"type": "float"
|
"type": "float",
|
||||||
|
"index": false
|
||||||
},
|
},
|
||||||
"width": {
|
"width": {
|
||||||
"type": "integer"
|
"type": "integer",
|
||||||
|
"index": false
|
||||||
},
|
},
|
||||||
"height": {
|
"height": {
|
||||||
"type": "integer"
|
"type": "integer",
|
||||||
|
"index": false
|
||||||
},
|
},
|
||||||
"mtime": {
|
"mtime": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
@@ -70,6 +79,23 @@
|
|||||||
"analyzer": "my_nGram",
|
"analyzer": "my_nGram",
|
||||||
"type": "text"
|
"type": "text"
|
||||||
},
|
},
|
||||||
|
"_keyword.*": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"_text.*": {
|
||||||
|
"analyzer": "content_analyzer",
|
||||||
|
"type": "text",
|
||||||
|
"fields": {
|
||||||
|
"nGram": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "my_nGram"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"_url": {
|
||||||
|
"type": "keyword",
|
||||||
|
"index": false
|
||||||
|
},
|
||||||
"content": {
|
"content": {
|
||||||
"analyzer": "content_analyzer",
|
"analyzer": "content_analyzer",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
@@ -83,6 +109,30 @@
|
|||||||
},
|
},
|
||||||
"tag": {
|
"tag": {
|
||||||
"type": "keyword"
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"exif_make": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"exif_model": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"exif:software": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"exif_exposure_time": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"exif_fnumber": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"exif_iso_speed_ratings": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"exif_focal_length": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"exif_user_comment": {
|
||||||
|
"type": "text"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
schema/pipeline.json
Normal file
10
schema/pipeline.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"description": "Copy _id to _tie",
|
||||||
|
"processors": [
|
||||||
|
{
|
||||||
|
"script": {
|
||||||
|
"source": "ctx._tie = ctx._id;"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -21,6 +21,12 @@
|
|||||||
"lowercase"
|
"lowercase"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"case_insensitive_kw_analyzer": {
|
||||||
|
"tokenizer": "keyword",
|
||||||
|
"filter": [
|
||||||
|
"lowercase"
|
||||||
|
]
|
||||||
|
},
|
||||||
"my_nGram": {
|
"my_nGram": {
|
||||||
"tokenizer": "my_nGram_tokenizer",
|
"tokenizer": "my_nGram_tokenizer",
|
||||||
"filter": [
|
"filter": [
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ THREADS=$(nproc)
|
|||||||
cd lib
|
cd lib
|
||||||
|
|
||||||
cd mupdf
|
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 ..
|
cd ..
|
||||||
|
|
||||||
mv mupdf/build/release/libmupdf.a .
|
mv mupdf/build/release/libmupdf.a .
|
||||||
@@ -13,8 +13,7 @@ mv mupdf/build/release/libmupdf-third.a .
|
|||||||
|
|
||||||
# openjp2
|
# openjp2
|
||||||
cd openjpeg
|
cd openjpeg
|
||||||
#cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3 -march=native -DNDEBUG"
|
cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3 -DNDEBUG -fPIC"
|
||||||
cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3"
|
|
||||||
make -j $THREADS
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv openjpeg/bin/libopenjp2.a .
|
mv openjpeg/bin/libopenjp2.a .
|
||||||
@@ -22,7 +21,7 @@ mv openjpeg/bin/libopenjp2.a .
|
|||||||
# harfbuzz
|
# harfbuzz
|
||||||
cd harfbuzz
|
cd harfbuzz
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure --disable-shared --enable-static
|
CFLAGS=-fPIC ./configure --disable-shared --enable-static
|
||||||
make -j $THREADS
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv harfbuzz/src/.libs/libharfbuzz.a .
|
mv harfbuzz/src/.libs/libharfbuzz.a .
|
||||||
@@ -33,7 +32,8 @@ cd ffmpeg
|
|||||||
--disable-ffprobe --disable-doc\
|
--disable-ffprobe --disable-doc\
|
||||||
--disable-manpages --disable-postproc --disable-avfilter \
|
--disable-manpages --disable-postproc --disable-avfilter \
|
||||||
--disable-alsa --disable-lzma --disable-xlib --disable-debug\
|
--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
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
@@ -74,7 +74,8 @@ mv libmagic/src/.libs/libmagic.a .
|
|||||||
cd tesseract
|
cd tesseract
|
||||||
mkdir build
|
mkdir build
|
||||||
cd 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" -DAUTO_OPTIMIZE=off ..
|
||||||
make -j $THREADS
|
make -j $THREADS
|
||||||
cd ../..
|
cd ../..
|
||||||
mv tesseract/build/libtesseract.a .
|
mv tesseract/build/libtesseract.a .
|
||||||
@@ -82,9 +83,46 @@ mv tesseract/build/libtesseract.a .
|
|||||||
# leptonica
|
# leptonica
|
||||||
cd leptonica
|
cd leptonica
|
||||||
./autogen.sh
|
./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 \
|
--without-giflib --without-libwebp --without-libwebpmux --without-libopenjpeg \
|
||||||
--enable-static --disable-shared
|
--enable-static --disable-shared
|
||||||
make -j $THREADS
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv leptonica/src/.libs/liblept.a .
|
mv leptonica/src/.libs/liblept.a .
|
||||||
|
|
||||||
|
# tiff
|
||||||
|
cd libtiff
|
||||||
|
./autogen.sh
|
||||||
|
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 .
|
||||||
|
|
||||||
|
# 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 .
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
cd lib
|
|
||||||
|
|
||||||
# mupdf
|
|
||||||
cd mupdf
|
|
||||||
HAVE_X11=no HAVE_GLUT=no gmake -j 4
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
mv mupdf/build/release/libmupdf.a .
|
|
||||||
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"
|
|
||||||
gmake -j 4
|
|
||||||
cd ..
|
|
||||||
mv openjpeg/bin/libopenjp2.a .
|
|
||||||
|
|
||||||
# harfbuzz
|
|
||||||
cd harfbuzz
|
|
||||||
./autogen.sh
|
|
||||||
./configure --disable-shared --enable-static
|
|
||||||
gmake -j 4
|
|
||||||
cd ..
|
|
||||||
mv harfbuzz/src/.libs/libharfbuzz.a .
|
|
||||||
|
|
||||||
# ffmpeg
|
|
||||||
cd ffmpeg
|
|
||||||
./configure --disable-shared --enable-static --disable-ffmpeg --disable-ffplay \
|
|
||||||
--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
|
|
||||||
gmake -j 4
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
mv ffmpeg/libavcodec/libavcodec.a .
|
|
||||||
mv ffmpeg/libavformat/libavformat.a .
|
|
||||||
mv ffmpeg/libavutil/libavutil.a .
|
|
||||||
mv ffmpeg/libswresample/libswresample.a .
|
|
||||||
mv ffmpeg/libswscale/libswscale.a .
|
|
||||||
|
|
||||||
#bzip2
|
|
||||||
cd bzip2-1.0.6
|
|
||||||
make -j 4
|
|
||||||
cd ..
|
|
||||||
mv bzip2-1.0.6/libbz2.a .
|
|
||||||
|
|
||||||
# magic
|
|
||||||
cd libmagic
|
|
||||||
./autogen.sh
|
|
||||||
./configure --enable-static --disable-shared
|
|
||||||
make -j 4
|
|
||||||
cd ..
|
|
||||||
mv libmagic/src/.libs/libmagic.a .
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
files = [
|
files = [
|
||||||
"schema/mappings.json",
|
"schema/mappings.json",
|
||||||
"schema/settings.json",
|
"schema/settings.json",
|
||||||
|
"schema/pipeline.json",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -9,6 +12,6 @@ def clean(filepath):
|
|||||||
|
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
with open(file, "rb") as f:
|
with open(file, "r") as f:
|
||||||
data = f.read()
|
data = json.dumps(json.load(f), separators=(",", ":")).encode()
|
||||||
print("char %s[%d] = {%s};" % (clean(file), len(data), ",".join(str(int(b)) for b in data)))
|
print("char %s[%d] = {%s};" % (clean(file), len(data), ",".join(str(int(b)) for b in data)))
|
||||||
|
|||||||
26
src/cli.c
26
src/cli.c
@@ -15,6 +15,13 @@
|
|||||||
#define DEFAULT_BIND_ADDR "localhost"
|
#define DEFAULT_BIND_ADDR "localhost"
|
||||||
#define DEFAULT_PORT "4090"
|
#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 *scan_args_create() {
|
||||||
scan_args_t *args = calloc(sizeof(scan_args_t), 1);
|
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) {
|
if (args->tesseract_lang != NULL) {
|
||||||
TessBaseAPI *api = TessBaseAPICreate();
|
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) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "Could not initialize tesseract with lang '%s'\n", args->tesseract_lang);
|
fprintf(stderr, "Could not initialize tesseract with lang '%s'\n", args->tesseract_lang);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
TessBaseAPIEnd(api);
|
TessBaseAPIEnd(api);
|
||||||
TessBaseAPIDelete(api);
|
TessBaseAPIDelete(api);
|
||||||
|
|
||||||
|
args->tesseract_path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUGF("cli.c", "arg quality=%f", args->quality)
|
LOG_DEBUGF("cli.c", "arg quality=%f", args->quality)
|
||||||
@@ -156,13 +173,16 @@ 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 depth=%d", args->depth)
|
||||||
LOG_DEBUGF("cli.c", "arg path=%s", args->path)
|
LOG_DEBUGF("cli.c", "arg path=%s", args->path)
|
||||||
LOG_DEBUGF("cli.c", "arg archive=%s", args->archive)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index_args_validate(index_args_t *args, int argc, const char **argv) {
|
int index_args_validate(index_args_t *args, int argc, const char **argv) {
|
||||||
|
|
||||||
|
LogCtx.verbose = 1;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "Required positional argument: PATH.\n");
|
fprintf(stderr, "Required positional argument: PATH.\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -224,6 +244,8 @@ int index_args_validate(index_args_t *args, int argc, const char **argv) {
|
|||||||
|
|
||||||
int web_args_validate(web_args_t *args, int argc, const char **argv) {
|
int web_args_validate(web_args_t *args, int argc, const char **argv) {
|
||||||
|
|
||||||
|
LogCtx.verbose = 1;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "Required positional argument: PATH.\n");
|
fprintf(stderr, "Required positional argument: PATH.\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ typedef struct scan_args {
|
|||||||
char *archive;
|
char *archive;
|
||||||
archive_mode_t archive_mode;
|
archive_mode_t archive_mode;
|
||||||
char *tesseract_lang;
|
char *tesseract_lang;
|
||||||
|
const char *tesseract_path;
|
||||||
} scan_args_t;
|
} scan_args_t;
|
||||||
|
|
||||||
scan_args_t *scan_args_create();
|
scan_args_t *scan_args_create();
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ struct {
|
|||||||
|
|
||||||
pthread_mutex_t mupdf_mu;
|
pthread_mutex_t mupdf_mu;
|
||||||
char * tesseract_lang;
|
char * tesseract_lang;
|
||||||
|
const char * tesseract_path;
|
||||||
} ScanCtx;
|
} ScanCtx;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ typedef struct es_indexer {
|
|||||||
|
|
||||||
static es_indexer_t *Indexer;
|
static es_indexer_t *Indexer;
|
||||||
|
|
||||||
|
void delete_queue(int max);
|
||||||
|
|
||||||
void print_json(cJSON *document, const char uuid_str[UUID_STR_LEN]) {
|
void print_json(cJSON *document, const char uuid_str[UUID_STR_LEN]) {
|
||||||
|
|
||||||
cJSON *line = cJSON_CreateObject();
|
cJSON *line = cJSON_CreateObject();
|
||||||
@@ -27,13 +29,14 @@ void print_json(cJSON *document, const char uuid_str[UUID_STR_LEN]) {
|
|||||||
cJSON_AddStringToObject(line, "_id", uuid_str);
|
cJSON_AddStringToObject(line, "_id", uuid_str);
|
||||||
cJSON_AddStringToObject(line, "_index", "sist2");
|
cJSON_AddStringToObject(line, "_index", "sist2");
|
||||||
cJSON_AddStringToObject(line, "_type", "_doc");
|
cJSON_AddStringToObject(line, "_type", "_doc");
|
||||||
cJSON_AddItemToObject(line, "_source", document);
|
cJSON_AddItemReferenceToObject(line, "_source", document);
|
||||||
|
|
||||||
char *json = cJSON_PrintUnformatted(line);
|
char *json = cJSON_PrintUnformatted(line);
|
||||||
|
|
||||||
printf("%s\n", json);
|
printf("%s\n", json);
|
||||||
|
|
||||||
cJSON_free(line);
|
cJSON_free(json);
|
||||||
|
cJSON_Delete(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void index_json(cJSON *document, const char uuid_str[UUID_STR_LEN]) {
|
void index_json(cJSON *document, const char uuid_str[UUID_STR_LEN]) {
|
||||||
@@ -63,12 +66,12 @@ void execute_update_script(const char *script, const char index_id[UUID_STR_LEN]
|
|||||||
cJSON *term_obj = cJSON_AddObjectToObject(query, "term");
|
cJSON *term_obj = cJSON_AddObjectToObject(query, "term");
|
||||||
cJSON_AddStringToObject(term_obj, "index", index_id);
|
cJSON_AddStringToObject(term_obj, "index", index_id);
|
||||||
|
|
||||||
char * str = cJSON_Print(body);
|
char *str = cJSON_Print(body);
|
||||||
|
|
||||||
char bulk_url[4096];
|
char bulk_url[4096];
|
||||||
snprintf(bulk_url, 4096, "%s/sist2/_update_by_query?pretty", Indexer->es_url);
|
snprintf(bulk_url, 4096, "%s/sist2/_update_by_query?pretty", Indexer->es_url);
|
||||||
response_t *r = web_post(bulk_url, str, "Content-Type: application/json");
|
response_t *r = web_post(bulk_url, str, "Content-Type: application/json");
|
||||||
printf("Executed user script <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Executed user script <%d>", r->status_code);
|
||||||
cJSON *resp = cJSON_Parse(r->body);
|
cJSON *resp = cJSON_Parse(r->body);
|
||||||
|
|
||||||
cJSON_free(str);
|
cJSON_free(str);
|
||||||
@@ -79,31 +82,25 @@ void execute_update_script(const char *script, const char index_id[UUID_STR_LEN]
|
|||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
char *error_str = cJSON_Print(error);
|
char *error_str = cJSON_Print(error);
|
||||||
|
|
||||||
fprintf(stderr, "User script error: \n%s\n", error_str);
|
LOG_ERRORF("elastic.c", "User script error: \n%s", error_str);
|
||||||
cJSON_free(error_str);
|
cJSON_free(error_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_Delete(resp);
|
cJSON_Delete(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void elastic_flush() {
|
void *create_bulk_buffer(int max, int *count, size_t *buf_len) {
|
||||||
|
|
||||||
if (Indexer == NULL) {
|
|
||||||
Indexer = create_indexer(IndexCtx.es_url);
|
|
||||||
}
|
|
||||||
|
|
||||||
es_bulk_line_t *line = Indexer->line_head;
|
es_bulk_line_t *line = Indexer->line_head;
|
||||||
|
*count = 0;
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
size_t buf_size = 0;
|
size_t buf_size = 0;
|
||||||
size_t buf_cur = 0;
|
size_t buf_cur = 0;
|
||||||
char *buf = malloc(1);
|
char *buf = malloc(1);
|
||||||
|
|
||||||
while (line != NULL) {
|
while (line != NULL && *count < max) {
|
||||||
char action_str[512];
|
char action_str[512];
|
||||||
snprintf(action_str, 512,
|
snprintf(action_str, 512,
|
||||||
"{\"index\":{\"_id\":\"%s\", \"_type\":\"_doc\", \"_index\":\"sist2\"}}\n", line->uuid_str);
|
"{\"index\":{\"_id\":\"%s\", \"_type\":\"_doc\", \"_index\":\"sist2\"}}\n", line->uuid_str);
|
||||||
size_t action_str_len = strlen(action_str);
|
size_t action_str_len = strlen(action_str);
|
||||||
|
|
||||||
size_t line_len = strlen(line->line);
|
size_t line_len = strlen(line->line);
|
||||||
@@ -115,47 +112,101 @@ void elastic_flush() {
|
|||||||
memcpy(buf + buf_cur, line->line, line_len);
|
memcpy(buf + buf_cur, line->line, line_len);
|
||||||
buf_cur += line_len;
|
buf_cur += line_len;
|
||||||
|
|
||||||
es_bulk_line_t *tmp = line;
|
|
||||||
line = line->next;
|
line = line->next;
|
||||||
free(tmp);
|
(*count)++;
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
buf = realloc(buf, buf_size + 1);
|
buf = realloc(buf, buf_size + 1);
|
||||||
*(buf+buf_cur) = '\0';
|
*(buf + buf_cur) = '\0';
|
||||||
|
|
||||||
Indexer->line_head = NULL;
|
*buf_len = buf_cur;
|
||||||
Indexer->line_tail = NULL;
|
return buf;
|
||||||
Indexer->queued = 0;
|
}
|
||||||
|
|
||||||
|
void _elastic_flush(int max) {
|
||||||
|
size_t buf_len;
|
||||||
|
int count;
|
||||||
|
void *buf = create_bulk_buffer(max, &count, &buf_len);
|
||||||
|
|
||||||
char bulk_url[4096];
|
char bulk_url[4096];
|
||||||
snprintf(bulk_url, 4096, "%s/sist2/_bulk", Indexer->es_url);
|
snprintf(bulk_url, 4096, "%s/sist2/_bulk?pipeline=tie", Indexer->es_url);
|
||||||
response_t *r = web_post(bulk_url, buf, "Content-Type: application/x-ndjson");
|
response_t *r = web_post(bulk_url, buf, "Content-Type: application/x-ndjson");
|
||||||
|
|
||||||
if (r->status_code == 0) {
|
if (r->status_code == 0) {
|
||||||
fprintf(stderr, "Could not connect to %s, make sure that elasticsearch is running!\n", IndexCtx.es_url);
|
LOG_FATALF("elastic.c", "Could not connect to %s, make sure that elasticsearch is running!\n", IndexCtx.es_url)
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Indexed %3d documents (%zukB) <%d>\n", count, buf_cur / 1024, r->status_code);
|
if (r->status_code == 413) {
|
||||||
|
|
||||||
cJSON *ret_json = cJSON_Parse(r->body);
|
if (max <= 1) {
|
||||||
if (cJSON_GetObjectItem(ret_json, "errors")->valueint != 0) {
|
LOG_ERRORF("elastic.c", "Single document too large, giving up: {%s}", Indexer->line_head->uuid_str)
|
||||||
cJSON *err;
|
free_response(r);
|
||||||
cJSON_ArrayForEach(err, cJSON_GetObjectItem(ret_json, "items")) {
|
free(buf);
|
||||||
if (cJSON_GetObjectItem(cJSON_GetObjectItem(err, "index"), "status")->valueint != 201) {
|
delete_queue(1);
|
||||||
char* str = cJSON_Print(err);
|
if (Indexer->queued != 0) {
|
||||||
fprintf(stderr, "%s\n", str);
|
elastic_flush();
|
||||||
cJSON_free(str);
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_WARNINGF("elastic.c", "Payload too large, retrying (%d documents)", count);
|
||||||
|
|
||||||
|
free_response(r);
|
||||||
|
free(buf);
|
||||||
|
_elastic_flush(max / 2);
|
||||||
|
return;
|
||||||
|
|
||||||
|
} else if (r->status_code != 200) {
|
||||||
|
cJSON *ret_json = cJSON_Parse(r->body);
|
||||||
|
if (cJSON_GetObjectItem(ret_json, "errors")->valueint != 0) {
|
||||||
|
cJSON *err;
|
||||||
|
cJSON_ArrayForEach(err, cJSON_GetObjectItem(ret_json, "items")) {
|
||||||
|
if (cJSON_GetObjectItem(cJSON_GetObjectItem(err, "index"), "status")->valueint != 201) {
|
||||||
|
char *str = cJSON_Print(err);
|
||||||
|
LOG_ERRORF("elastic.c", "%s\n", str);
|
||||||
|
cJSON_free(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_Delete(ret_json);
|
||||||
|
delete_queue(Indexer->queued);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
LOG_INFOF("elastic.c", "Indexed %d documents (%zukB) <%d>", count, buf_len / 1024, r->status_code);
|
||||||
|
|
||||||
|
delete_queue(max);
|
||||||
|
|
||||||
|
if (Indexer->queued != 0) {
|
||||||
|
elastic_flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_Delete(ret_json);
|
|
||||||
|
|
||||||
free_response(r);
|
free_response(r);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void delete_queue(int max) {
|
||||||
|
for (int i = 0; i < max; i++) {
|
||||||
|
es_bulk_line_t *tmp = Indexer->line_head;
|
||||||
|
Indexer->line_head = tmp->next;
|
||||||
|
if (Indexer->line_head == NULL) {
|
||||||
|
Indexer->line_tail = NULL;
|
||||||
|
} else {
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
Indexer->queued -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void elastic_flush() {
|
||||||
|
|
||||||
|
if (Indexer == NULL) {
|
||||||
|
Indexer = create_indexer(IndexCtx.es_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
_elastic_flush(Indexer->queued);
|
||||||
|
}
|
||||||
|
|
||||||
void elastic_index_line(es_bulk_line_t *line) {
|
void elastic_index_line(es_bulk_line_t *line) {
|
||||||
|
|
||||||
if (Indexer == NULL) {
|
if (Indexer == NULL) {
|
||||||
@@ -192,13 +243,13 @@ es_indexer_t *create_indexer(const char *url) {
|
|||||||
return indexer;
|
return indexer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_indexer(char * script, char index_id[UUID_STR_LEN]) {
|
void destroy_indexer(char *script, char index_id[UUID_STR_LEN]) {
|
||||||
|
|
||||||
char url[4096];
|
char url[4096];
|
||||||
|
|
||||||
snprintf(url, sizeof(url), "%s/sist2/_refresh", IndexCtx.es_url);
|
snprintf(url, sizeof(url), "%s/sist2/_refresh", IndexCtx.es_url);
|
||||||
response_t *r = web_post(url, "", NULL);
|
response_t *r = web_post(url, "", NULL);
|
||||||
printf("Refresh index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Refresh index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
if (script != NULL) {
|
if (script != NULL) {
|
||||||
@@ -207,12 +258,12 @@ void destroy_indexer(char * script, char index_id[UUID_STR_LEN]) {
|
|||||||
|
|
||||||
snprintf(url, sizeof(url), "%s/sist2/_refresh", IndexCtx.es_url);
|
snprintf(url, sizeof(url), "%s/sist2/_refresh", IndexCtx.es_url);
|
||||||
r = web_post(url, "", NULL);
|
r = web_post(url, "", NULL);
|
||||||
printf("Refresh index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Refresh index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, sizeof(url), "%s/sist2/_forcemerge", IndexCtx.es_url);
|
snprintf(url, sizeof(url), "%s/sist2/_forcemerge", IndexCtx.es_url);
|
||||||
r = web_post(url, "", NULL);
|
r = web_post(url, "", NULL);
|
||||||
printf("Merge index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Merge index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
if (Indexer != NULL) {
|
if (Indexer != NULL) {
|
||||||
@@ -232,32 +283,37 @@ void elastic_init(int force_reset) {
|
|||||||
|
|
||||||
if (!index_exists || force_reset) {
|
if (!index_exists || force_reset) {
|
||||||
r = web_delete(url);
|
r = web_delete(url);
|
||||||
printf("Delete index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Delete index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, 4096, "%s/sist2", IndexCtx.es_url);
|
snprintf(url, 4096, "%s/sist2", IndexCtx.es_url);
|
||||||
r = web_put(url, "", NULL);
|
r = web_put(url, "", NULL);
|
||||||
printf("Create index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Create index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, 4096, "%s/sist2/_close", IndexCtx.es_url);
|
snprintf(url, 4096, "%s/sist2/_close", IndexCtx.es_url);
|
||||||
r = web_post(url, "", NULL);
|
r = web_post(url, "", NULL);
|
||||||
printf("Close index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Close index <%d>", r->status_code);
|
||||||
|
free_response(r);
|
||||||
|
|
||||||
|
snprintf(url, 4096, "%s/_ingest/pipeline/tie", IndexCtx.es_url);
|
||||||
|
r = web_put(url, pipeline_json, "Content-Type: application/json");
|
||||||
|
LOG_INFOF("elastic.c", "Create pipeline <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, 4096, "%s/sist2/_settings", IndexCtx.es_url);
|
snprintf(url, 4096, "%s/sist2/_settings", IndexCtx.es_url);
|
||||||
r = web_put(url, settings_json, "Content-Type: application/json");
|
r = web_put(url, settings_json, "Content-Type: application/json");
|
||||||
printf("Update settings <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Update settings <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, 4096, "%s/sist2/_mappings/_doc?include_type_name=true", IndexCtx.es_url);
|
snprintf(url, 4096, "%s/sist2/_mappings/_doc?include_type_name=true", IndexCtx.es_url);
|
||||||
r = web_put(url, mappings_json, "Content-Type: application/json");
|
r = web_put(url, mappings_json, "Content-Type: application/json");
|
||||||
printf("Update mappings <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Update mappings <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, 4096, "%s/sist2/_open", IndexCtx.es_url);
|
snprintf(url, 4096, "%s/sist2/_open", IndexCtx.es_url);
|
||||||
r = web_post(url, "", NULL);
|
r = web_post(url, "", NULL);
|
||||||
printf("Open index <%d>\n", r->status_code);
|
LOG_INFOF("elastic.c", "Open index <%d>", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,3 +330,28 @@ cJSON *elastic_get_document(const char *uuid_str) {
|
|||||||
free_response(r);
|
free_response(r);
|
||||||
return json;
|
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);
|
cJSON *elastic_get_document(const char *uuid_str);
|
||||||
|
|
||||||
|
char *elastic_get_status();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -34,6 +34,7 @@ void write_index_descriptor(char *path, index_descriptor_t *desc) {
|
|||||||
cJSON_AddStringToObject(json, "version", desc->version);
|
cJSON_AddStringToObject(json, "version", desc->version);
|
||||||
cJSON_AddStringToObject(json, "root", desc->root);
|
cJSON_AddStringToObject(json, "root", desc->root);
|
||||||
cJSON_AddStringToObject(json, "name", desc->name);
|
cJSON_AddStringToObject(json, "name", desc->name);
|
||||||
|
cJSON_AddStringToObject(json, "type", desc->type);
|
||||||
cJSON_AddStringToObject(json, "rewrite_url", desc->rewrite_url);
|
cJSON_AddStringToObject(json, "rewrite_url", desc->rewrite_url);
|
||||||
cJSON_AddNumberToObject(json, "timestamp", (double) desc->timestamp);
|
cJSON_AddNumberToObject(json, "timestamp", (double) desc->timestamp);
|
||||||
|
|
||||||
@@ -56,8 +57,7 @@ index_descriptor_t read_index_descriptor(char *path) {
|
|||||||
int fd = open(path, O_RDONLY);
|
int fd = open(path, O_RDONLY);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
fprintf(stderr, "Invalid/corrupt index (Could not find descriptor)\n");
|
LOG_FATAL("serialize.c", "Invalid/corrupt index (Could not find descriptor)\n")
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *buf = malloc(info.st_size + 1);
|
char *buf = malloc(info.st_size + 1);
|
||||||
@@ -75,6 +75,11 @@ index_descriptor_t read_index_descriptor(char *path) {
|
|||||||
descriptor.root_len = (short) strlen(descriptor.root);
|
descriptor.root_len = (short) strlen(descriptor.root);
|
||||||
strcpy(descriptor.version, cJSON_GetObjectItem(json, "version")->valuestring);
|
strcpy(descriptor.version, cJSON_GetObjectItem(json, "version")->valuestring);
|
||||||
strcpy(descriptor.uuid, cJSON_GetObjectItem(json, "uuid")->valuestring);
|
strcpy(descriptor.uuid, cJSON_GetObjectItem(json, "uuid")->valuestring);
|
||||||
|
if (cJSON_GetObjectItem(json, "type") == NULL) {
|
||||||
|
strcpy(descriptor.type, INDEX_TYPE_BIN);
|
||||||
|
} else {
|
||||||
|
strcpy(descriptor.type, cJSON_GetObjectItem(json, "type")->valuestring);
|
||||||
|
}
|
||||||
|
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
free(buf);
|
free(buf);
|
||||||
@@ -113,6 +118,24 @@ char *get_meta_key_text(enum metakey meta_key) {
|
|||||||
return "font_name";
|
return "font_name";
|
||||||
case MetaParent:
|
case MetaParent:
|
||||||
return "parent";
|
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";
|
||||||
|
case MetaExifDateTime:
|
||||||
|
return "exif_datetime";
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -172,8 +195,8 @@ void thread_cleanup() {
|
|||||||
close(index_fd);
|
close(index_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func func) {
|
|
||||||
|
|
||||||
|
void read_index_bin(const char *path, const char *index_id, index_func func) {
|
||||||
line_t line;
|
line_t line;
|
||||||
dyn_buffer_t buf = dyn_buffer_create();
|
dyn_buffer_t buf = dyn_buffer_create();
|
||||||
|
|
||||||
@@ -191,7 +214,12 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
char uuid_str[UUID_STR_LEN];
|
char uuid_str[UUID_STR_LEN];
|
||||||
uuid_unparse(line.uuid, uuid_str);
|
uuid_unparse(line.uuid, uuid_str);
|
||||||
|
|
||||||
cJSON_AddStringToObject(document, "mime", mime_get_mime_text(line.mime));
|
const char* mime_text = mime_get_mime_text(line.mime);
|
||||||
|
if (mime_text == NULL) {
|
||||||
|
cJSON_AddNullToObject(document, "mime");
|
||||||
|
} else {
|
||||||
|
cJSON_AddStringToObject(document, "mime", mime_get_mime_text(line.mime));
|
||||||
|
}
|
||||||
cJSON_AddNumberToObject(document, "size", (double) line.size);
|
cJSON_AddNumberToObject(document, "size", (double) line.size);
|
||||||
cJSON_AddNumberToObject(document, "mtime", line.mtime);
|
cJSON_AddNumberToObject(document, "mtime", line.mtime);
|
||||||
|
|
||||||
@@ -229,7 +257,7 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
case MetaMediaBitrate: {
|
case MetaMediaBitrate: {
|
||||||
long value;
|
long value;
|
||||||
fread(&value, sizeof(long), 1, file);
|
fread(&value, sizeof(long), 1, file);
|
||||||
cJSON_AddNumberToObject(document, get_meta_key_text(key), value);
|
cJSON_AddNumberToObject(document, get_meta_key_text(key), (double) value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MetaMediaAudioCodec:
|
case MetaMediaAudioCodec:
|
||||||
@@ -250,6 +278,15 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
case MetaGenre:
|
case MetaGenre:
|
||||||
case MetaFontName:
|
case MetaFontName:
|
||||||
case MetaParent:
|
case MetaParent:
|
||||||
|
case MetaExifMake:
|
||||||
|
case MetaExifSoftware:
|
||||||
|
case MetaExifExposureTime:
|
||||||
|
case MetaExifFNumber:
|
||||||
|
case MetaExifFocalLength:
|
||||||
|
case MetaExifUserComment:
|
||||||
|
case MetaExifIsoSpeedRatings:
|
||||||
|
case MetaExifDateTime:
|
||||||
|
case MetaExifModel:
|
||||||
case MetaTitle: {
|
case MetaTitle: {
|
||||||
buf.cur = 0;
|
buf.cur = 0;
|
||||||
while ((c = getc(file)) != 0) {
|
while ((c = getc(file)) != 0) {
|
||||||
@@ -262,7 +299,7 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
LOG_FATALF("serialize.c", "Invalid meta key (corrupt index): %x", key)
|
LOG_FATALF("serialize.c", "Invalid meta key (corrupt index): %x", key)
|
||||||
}
|
}
|
||||||
|
|
||||||
key = getc(file);
|
key = getc(file);
|
||||||
@@ -275,6 +312,89 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *json_type_copy_fields[] = {
|
||||||
|
"mime", "name", "path", "extension", "index", "size", "mtime", "parent",
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
"title", "content", "width", "height", "duration", "audioc", "videoc",
|
||||||
|
"bitrate", "artist", "album", "album_artist", "genre", "title", "font_name",
|
||||||
|
|
||||||
|
// Special
|
||||||
|
"tag", "_url"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *json_type_array_fields[] = {
|
||||||
|
"_keyword", "_text"
|
||||||
|
};
|
||||||
|
|
||||||
|
void read_index_json(const char *path, UNUSED(const char *index_id), index_func func) {
|
||||||
|
|
||||||
|
FILE *file = fopen(path, "r");
|
||||||
|
while (1) {
|
||||||
|
char *line = NULL;
|
||||||
|
size_t len;
|
||||||
|
size_t read = getline(&line, &len, file);
|
||||||
|
if (read == -1) {
|
||||||
|
if (line) {
|
||||||
|
free(line);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *input = cJSON_Parse(line);
|
||||||
|
if (input == NULL) {
|
||||||
|
LOG_FATALF("serialize.c", "Could not parse JSON line: \n%s", line)
|
||||||
|
}
|
||||||
|
if (line) {
|
||||||
|
free(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *document = cJSON_CreateObject();
|
||||||
|
const char *uuid_str = cJSON_GetObjectItem(input, "_id")->valuestring;
|
||||||
|
|
||||||
|
for (int i = 0; i < (sizeof(json_type_copy_fields) / sizeof(json_type_copy_fields[0])); i++) {
|
||||||
|
cJSON *value = cJSON_GetObjectItem(input, json_type_copy_fields[i]);
|
||||||
|
if (value != NULL) {
|
||||||
|
cJSON_AddItemReferenceToObject(document, json_type_copy_fields[i], value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < (sizeof(json_type_array_fields) / sizeof(json_type_array_fields[0])); i++) {
|
||||||
|
cJSON *arr = cJSON_GetObjectItem(input, json_type_array_fields[i]);
|
||||||
|
if (arr != NULL) {
|
||||||
|
cJSON *obj;
|
||||||
|
cJSON_ArrayForEach(obj, arr) {
|
||||||
|
char key[1024];
|
||||||
|
cJSON *k = cJSON_GetObjectItem(obj, "k");
|
||||||
|
cJSON *v = cJSON_GetObjectItem(obj, "v");
|
||||||
|
if (k == NULL || v == NULL || !cJSON_IsString(k) || !cJSON_IsString(v)) {
|
||||||
|
char *str = cJSON_Print(obj);
|
||||||
|
LOG_FATALF("serialize.c", "Invalid %s member: must contain .k and .v string fields: \n%s",
|
||||||
|
json_type_array_fields[i], str)
|
||||||
|
}
|
||||||
|
snprintf(key, sizeof(key), "%s.%s", json_type_array_fields[i], k->valuestring);
|
||||||
|
cJSON_AddStringToObject(document, key, v->valuestring);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func(document, uuid_str);
|
||||||
|
cJSON_Delete(document);
|
||||||
|
cJSON_Delete(input);
|
||||||
|
|
||||||
|
}
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void read_index(const char *path, const char index_id[UUID_STR_LEN], const char *type, index_func func) {
|
||||||
|
|
||||||
|
if (strcmp(type, INDEX_TYPE_BIN) == 0) {
|
||||||
|
read_index_bin(path, index_id, func);
|
||||||
|
} else if (strcmp(type, INDEX_TYPE_JSON) == 0) {
|
||||||
|
read_index_json(path, index_id, func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void incremental_read(GHashTable *table, const char *filepath) {
|
void incremental_read(GHashTable *table, const char *filepath) {
|
||||||
FILE *file = fopen(filepath, "rb");
|
FILE *file = fopen(filepath, "rb");
|
||||||
line_t line;
|
line_t line;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ void incremental_copy(store_t *store, store_t *dst_store, const char *filepath,
|
|||||||
|
|
||||||
void write_document(document_t *doc);
|
void write_document(document_t *doc);
|
||||||
|
|
||||||
void read_index(const char *path, const char[UUID_STR_LEN], index_func);
|
void read_index(const char *path, const char[UUID_STR_LEN], const char *type, index_func);
|
||||||
|
|
||||||
void incremental_read(GHashTable *table, const char *filepath);
|
void incremental_read(GHashTable *table, const char *filepath);
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ void sist_logf(char *filepath, int level, char *format, ...) {
|
|||||||
log_len += 1;
|
log_len += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
write(STDOUT_FILENO, log_str, log_len);
|
write(STDERR_FILENO, log_str, log_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sist_log(char *filepath, int level, char *str) {
|
void sist_log(char *filepath, int level, char *str) {
|
||||||
|
|||||||
15
src/main.c
15
src/main.c
@@ -6,7 +6,7 @@
|
|||||||
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
||||||
|
|
||||||
|
|
||||||
static const char *const Version = "1.2.0";
|
static const char *const Version = "1.2.13";
|
||||||
static const char *const usage[] = {
|
static const char *const usage[] = {
|
||||||
"sist2 scan [OPTION]... PATH",
|
"sist2 scan [OPTION]... PATH",
|
||||||
"sist2 index [OPTION]... INDEX",
|
"sist2 index [OPTION]... INDEX",
|
||||||
@@ -29,6 +29,7 @@ void init_dir(const char *dirpath) {
|
|||||||
uuid_unparse(uuid, ScanCtx.index.desc.uuid);
|
uuid_unparse(uuid, ScanCtx.index.desc.uuid);
|
||||||
time(&ScanCtx.index.desc.timestamp);
|
time(&ScanCtx.index.desc.timestamp);
|
||||||
strcpy(ScanCtx.index.desc.version, Version);
|
strcpy(ScanCtx.index.desc.version, Version);
|
||||||
|
strcpy(ScanCtx.index.desc.type, INDEX_TYPE_BIN);
|
||||||
|
|
||||||
write_index_descriptor(path, &ScanCtx.index.desc);
|
write_index_descriptor(path, &ScanCtx.index.desc);
|
||||||
}
|
}
|
||||||
@@ -48,8 +49,10 @@ void sist2_scan(scan_args_t *args) {
|
|||||||
strncpy(ScanCtx.index.path, args->output, sizeof(ScanCtx.index.path));
|
strncpy(ScanCtx.index.path, args->output, sizeof(ScanCtx.index.path));
|
||||||
strncpy(ScanCtx.index.desc.name, args->name, sizeof(ScanCtx.index.desc.name));
|
strncpy(ScanCtx.index.desc.name, args->name, sizeof(ScanCtx.index.desc.name));
|
||||||
strncpy(ScanCtx.index.desc.root, args->path, sizeof(ScanCtx.index.desc.root));
|
strncpy(ScanCtx.index.desc.root, args->path, sizeof(ScanCtx.index.desc.root));
|
||||||
|
strncpy(ScanCtx.index.desc.rewrite_url, args->rewrite_url, sizeof(ScanCtx.index.desc.rewrite_url));
|
||||||
ScanCtx.index.desc.root_len = (short) strlen(ScanCtx.index.desc.root);
|
ScanCtx.index.desc.root_len = (short) strlen(ScanCtx.index.desc.root);
|
||||||
ScanCtx.tesseract_lang = args->tesseract_lang;
|
ScanCtx.tesseract_lang = args->tesseract_lang;
|
||||||
|
ScanCtx.tesseract_path = args->tesseract_path;
|
||||||
|
|
||||||
init_dir(ScanCtx.index.path);
|
init_dir(ScanCtx.index.path);
|
||||||
|
|
||||||
@@ -130,8 +133,12 @@ void sist2_index(index_args_t *args) {
|
|||||||
snprintf(descriptor_path, PATH_MAX, "%s/descriptor.json", args->index_path);
|
snprintf(descriptor_path, PATH_MAX, "%s/descriptor.json", args->index_path);
|
||||||
|
|
||||||
index_descriptor_t desc = read_index_descriptor(descriptor_path);
|
index_descriptor_t desc = read_index_descriptor(descriptor_path);
|
||||||
if (strcmp(desc.version, Version) != 0) {
|
|
||||||
fprintf(stderr, "Version mismatch! Index is v%s but executable is v%s\n", desc.version, Version);
|
LOG_DEBUGF("main.c", "descriptor version %s (%s)", desc.version, desc.type)
|
||||||
|
|
||||||
|
if (strcmp(desc.version, Version) != 0 && strcmp(desc.version, INDEX_VERSION_EXTERNAL) != 0) {
|
||||||
|
fprintf(stderr, "Version mismatch! Index is %s but executable is %s/%s\n",
|
||||||
|
desc.version, Version, INDEX_VERSION_EXTERNAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +160,7 @@ void sist2_index(index_args_t *args) {
|
|||||||
if (strncmp(de->d_name, "_index_", sizeof("_index_") - 1) == 0) {
|
if (strncmp(de->d_name, "_index_", sizeof("_index_") - 1) == 0) {
|
||||||
char file_path[PATH_MAX];
|
char file_path[PATH_MAX];
|
||||||
snprintf(file_path, PATH_MAX, "%s/%s", args->index_path, de->d_name);
|
snprintf(file_path, PATH_MAX, "%s/%s", args->index_path, de->d_name);
|
||||||
read_index(file_path, desc.uuid, f);
|
read_index(file_path, desc.uuid, desc.type, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
#include "doc.h"
|
#include "doc.h"
|
||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
|
|
||||||
void dump_text(mceTextReader_t *reader, dyn_buffer_t *buf) {
|
int dump_text(mceTextReader_t *reader, dyn_buffer_t *buf) {
|
||||||
|
|
||||||
mce_skip_attributes(reader);
|
mce_skip_attributes(reader);
|
||||||
|
|
||||||
|
xmlErrorPtr err = xmlGetLastError();
|
||||||
|
if (err != NULL) {
|
||||||
|
if (err->level == XML_ERR_FATAL) {
|
||||||
|
LOG_ERRORF("doc.c", "Got fatal XML error while parsing document: %s", err->message)
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
LOG_ERRORF("doc.c", "Got recoverable XML error while parsing document: %s", err->message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mce_start_children(reader) {
|
mce_start_children(reader) {
|
||||||
mce_start_element(reader, NULL, _X("t")) {
|
mce_start_element(reader, NULL, _X("t")) {
|
||||||
mce_skip_attributes(reader);
|
mce_skip_attributes(reader);
|
||||||
@@ -18,10 +28,14 @@ void dump_text(mceTextReader_t *reader, dyn_buffer_t *buf) {
|
|||||||
} mce_end_element(reader);
|
} mce_end_element(reader);
|
||||||
|
|
||||||
mce_start_element(reader, NULL, NULL) {
|
mce_start_element(reader, NULL, NULL) {
|
||||||
dump_text(reader, buf);
|
int ret = dump_text(reader, buf);
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
} mce_end_element(reader);
|
} mce_end_element(reader);
|
||||||
|
|
||||||
} mce_end_children(reader)
|
} mce_end_children(reader)
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
@@ -52,23 +66,28 @@ int should_read_part(opcPart part) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
void read_part(opcContainer *c, dyn_buffer_t *buf, opcPart part, document_t *doc) {
|
int read_part(opcContainer *c, dyn_buffer_t *buf, opcPart part, document_t *doc) {
|
||||||
|
|
||||||
mceTextReader_t reader;
|
mceTextReader_t reader;
|
||||||
int ret = opcXmlReaderOpen(c, &reader, part, NULL, "UTF-8", 0);
|
int ret = opcXmlReaderOpen(c, &reader, part, NULL, "UTF-8", XML_PARSE_NOWARNING | XML_PARSE_NOERROR | XML_PARSE_NONET);
|
||||||
|
|
||||||
if (ret != OPC_ERROR_NONE) {
|
if (ret != OPC_ERROR_NONE) {
|
||||||
LOG_ERRORF(doc->filepath, "(doc.c) opcXmlReaderOpen() returned error code %d", ret);
|
LOG_ERRORF(doc->filepath, "(doc.c) opcXmlReaderOpen() returned error code %d", ret);
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mce_start_document(&reader) {
|
mce_start_document(&reader) {
|
||||||
mce_start_element(&reader, NULL, NULL) {
|
mce_start_element(&reader, NULL, NULL) {
|
||||||
dump_text(&reader, buf);
|
ret = dump_text(&reader, buf);
|
||||||
|
if (ret != 0) {
|
||||||
|
mceTextReaderCleanup(&reader);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} mce_end_element(&reader);
|
} mce_end_element(&reader);
|
||||||
} mce_end_document(&reader);
|
} mce_end_document(&reader);
|
||||||
|
|
||||||
mceTextReaderCleanup(&reader);
|
mceTextReaderCleanup(&reader);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_doc(void *mem, size_t mem_len, document_t *doc) {
|
void parse_doc(void *mem, size_t mem_len, document_t *doc) {
|
||||||
@@ -88,7 +107,10 @@ void parse_doc(void *mem, size_t mem_len, document_t *doc) {
|
|||||||
opcPart part = opcPartGetFirst(c);
|
opcPart part = opcPartGetFirst(c);
|
||||||
do {
|
do {
|
||||||
if (should_read_part(part)) {
|
if (should_read_part(part)) {
|
||||||
read_part(c, &buf, part, doc);
|
int ret = read_part(c, &buf, part, doc);
|
||||||
|
if (ret != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while ((part = opcPartGetNext(c, part)));
|
} while ((part = opcPartGetNext(c, part)));
|
||||||
|
|
||||||
|
|||||||
@@ -193,6 +193,24 @@ append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *doc,
|
|||||||
APPEND_TAG_META(doc, tag, MetaArtist)
|
APPEND_TAG_META(doc, tag, MetaArtist)
|
||||||
} else if (strcmp(tag->key, "ImageDescription") == 0) {
|
} else if (strcmp(tag->key, "ImageDescription") == 0) {
|
||||||
APPEND_TAG_META(doc, tag, MetaContent)
|
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)
|
||||||
|
} else if (strcmp(tag->key, "DateTime") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaExifDateTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1293,6 +1293,7 @@ g_hash_table_insert(ext_table, "isu", (gpointer)video_x_isvideo);
|
|||||||
g_hash_table_insert(ext_table, "mjpg", (gpointer)video_x_motion_jpeg);
|
g_hash_table_insert(ext_table, "mjpg", (gpointer)video_x_motion_jpeg);
|
||||||
g_hash_table_insert(ext_table, "asf", (gpointer)video_x_ms_asf);
|
g_hash_table_insert(ext_table, "asf", (gpointer)video_x_ms_asf);
|
||||||
g_hash_table_insert(ext_table, "asx", (gpointer)video_x_ms_asf);
|
g_hash_table_insert(ext_table, "asx", (gpointer)video_x_ms_asf);
|
||||||
|
g_hash_table_insert(ext_table, "wmv", (gpointer)video_x_ms_asf);
|
||||||
g_hash_table_insert(ext_table, "qtc", (gpointer)video_x_qtc);
|
g_hash_table_insert(ext_table, "qtc", (gpointer)video_x_qtc);
|
||||||
g_hash_table_insert(ext_table, "movie", (gpointer)video_x_sgi_movie);
|
g_hash_table_insert(ext_table, "movie", (gpointer)video_x_sgi_movie);
|
||||||
g_hash_table_insert(ext_table, "mv", (gpointer)video_x_sgi_movie);
|
g_hash_table_insert(ext_table, "mv", (gpointer)video_x_sgi_movie);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#include "pdf.h"
|
#include "pdf.h"
|
||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
|
|
||||||
#define MIN_OCR_SIZE 128
|
#define MIN_OCR_SIZE 350
|
||||||
|
#define MIN_OCR_LEN 10
|
||||||
__thread text_buffer_t thread_buffer;
|
__thread text_buffer_t thread_buffer;
|
||||||
|
|
||||||
|
|
||||||
@@ -82,7 +83,8 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
|||||||
fz_drop_pixmap(ctx, pixmap);
|
fz_drop_pixmap(ctx, pixmap);
|
||||||
|
|
||||||
if (err != 0) {
|
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);
|
fz_drop_page(ctx, cover);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -127,37 +129,40 @@ int read_stext_block(fz_stext_block *block, text_buffer_t *tex) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define IS_VALID_BPP(d) (d==1 || d==2 || d==4 || d==8 || d==16 || d==24 || d==32)
|
||||||
|
|
||||||
void fill_image(fz_context *ctx, UNUSED(fz_device *dev),
|
void fill_image(fz_context *ctx, UNUSED(fz_device *dev),
|
||||||
fz_image *img, UNUSED(fz_matrix ctm), UNUSED(float alpha),
|
fz_image *img, UNUSED(fz_matrix ctm), UNUSED(float alpha),
|
||||||
UNUSED(fz_color_params color_params)) {
|
UNUSED(fz_color_params color_params)) {
|
||||||
|
|
||||||
int l2factor = 0;
|
int l2factor = 0;
|
||||||
|
|
||||||
if (img->w > MIN_OCR_SIZE && img->h > MIN_OCR_SIZE) {
|
if (img->w > MIN_OCR_SIZE && img->h > MIN_OCR_SIZE && IS_VALID_BPP(img->n)) {
|
||||||
|
|
||||||
fz_pixmap *pix = img->get_pixmap(ctx, img, NULL, img->w, img->h, &l2factor);
|
fz_pixmap *pix = img->get_pixmap(ctx, img, NULL, img->w, img->h, &l2factor);
|
||||||
|
|
||||||
if (pix->h > MIN_OCR_SIZE && img->h > MIN_OCR_SIZE && img->xres != 0) {
|
if (pix->h > MIN_OCR_SIZE && img->h > MIN_OCR_SIZE && img->xres != 0) {
|
||||||
TessBaseAPI *api = TessBaseAPICreate();
|
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);
|
TessBaseAPISetImage(api, pix->samples, pix->w, pix->h, pix->n, pix->stride);
|
||||||
TessBaseAPISetSourceResolution(api, pix->xres);
|
TessBaseAPISetSourceResolution(api, pix->xres);
|
||||||
|
|
||||||
char *text = TessBaseAPIGetUTF8Text(api);
|
char *text = TessBaseAPIGetUTF8Text(api);
|
||||||
size_t len = strlen(text);
|
size_t len = strlen(text);
|
||||||
text_buffer_append_string(&thread_buffer, text, len - 1);
|
if (len >= MIN_OCR_LEN) {
|
||||||
LOG_DEBUGF(
|
text_buffer_append_string(&thread_buffer, text, len - 1);
|
||||||
"pdf.c",
|
LOG_DEBUGF(
|
||||||
"(OCR) %dx%d got %dB from tesseract (%s), buffer:%dB",
|
"pdf.c",
|
||||||
pix->w, pix->h, len, ScanCtx.tesseract_lang, thread_buffer.dyn_buffer.cur
|
"(OCR) %dx%d got %dB from tesseract (%s), buffer:%dB",
|
||||||
)
|
pix->w, pix->h, len, ScanCtx.tesseract_lang, thread_buffer.dyn_buffer.cur
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
TessBaseAPIEnd(api);
|
TessBaseAPIEnd(api);
|
||||||
TessBaseAPIDelete(api);
|
TessBaseAPIDelete(api);
|
||||||
fz_drop_pixmap(ctx, pix);
|
|
||||||
}
|
}
|
||||||
|
fz_drop_pixmap(ctx, pix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#define SIST2_PDF_H
|
#define SIST2_PDF_H
|
||||||
|
|
||||||
#include "src/sist.h"
|
#include "src/sist.h"
|
||||||
#include <tesseract/capi.h>
|
|
||||||
|
|
||||||
|
|
||||||
void parse_pdf(void *buf, size_t buf_len, document_t *doc);
|
void parse_pdf(void *buf, size_t buf_len, document_t *doc);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#define UUID_STR_LEN 37
|
#define UUID_STR_LEN 37
|
||||||
#define UNUSED(x) __attribute__((__unused__)) x
|
#define UNUSED(x) __attribute__((__unused__)) x
|
||||||
#define TESS_DATAPATH "/usr/share/tessdata/"
|
|
||||||
|
|
||||||
#include <glib-2.0/glib.h>
|
#include <glib-2.0/glib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -34,6 +33,8 @@
|
|||||||
#include <archive_entry.h>
|
#include <archive_entry.h>
|
||||||
#include <opc/opc.h>
|
#include <opc/opc.h>
|
||||||
#include <libxml/xmlstring.h>
|
#include <libxml/xmlstring.h>
|
||||||
|
#define BOOL int
|
||||||
|
#include <tesseract/capi.h>
|
||||||
|
|
||||||
#include <onion/onion.h>
|
#include <onion/onion.h>
|
||||||
#include <onion/handler.h>
|
#include <onion/handler.h>
|
||||||
|
|||||||
23
src/types.h
23
src/types.h
@@ -2,9 +2,9 @@
|
|||||||
#define SIST2_TYPES_H
|
#define SIST2_TYPES_H
|
||||||
|
|
||||||
|
|
||||||
#define META_INT_MASK 0xF0
|
#define META_INT_MASK 0x80
|
||||||
#define META_STR_MASK 0xE0
|
#define META_STR_MASK 0x40
|
||||||
#define META_LONG_MASK 0xD0
|
#define META_LONG_MASK 0x20
|
||||||
#define IS_META_INT(key) (key & META_INT_MASK) == META_INT_MASK
|
#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_LONG(key) (key & META_LONG_MASK) == META_LONG_MASK
|
||||||
#define IS_META_STR(meta) (meta->key & META_STR_MASK) == META_STR_MASK
|
#define IS_META_STR(meta) (meta->key & META_STR_MASK) == META_STR_MASK
|
||||||
@@ -31,16 +31,31 @@ enum metakey {
|
|||||||
MetaTitle = 12 | META_STR_MASK,
|
MetaTitle = 12 | META_STR_MASK,
|
||||||
MetaFontName = 13 | META_STR_MASK,
|
MetaFontName = 13 | META_STR_MASK,
|
||||||
MetaParent = 14 | 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,
|
||||||
|
MetaExifDateTime = 23 | META_STR_MASK,
|
||||||
|
//Note to self: this will break after 31 entries
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define INDEX_TYPE_BIN "binary"
|
||||||
|
#define INDEX_TYPE_JSON "json"
|
||||||
|
#define INDEX_VERSION_EXTERNAL "_external_v1"
|
||||||
|
|
||||||
typedef struct index_descriptor {
|
typedef struct index_descriptor {
|
||||||
char uuid[UUID_STR_LEN];
|
char uuid[UUID_STR_LEN];
|
||||||
char version[6];
|
char version[64];
|
||||||
long timestamp;
|
long timestamp;
|
||||||
char root[PATH_MAX];
|
char root[PATH_MAX];
|
||||||
char rewrite_url[8196];
|
char rewrite_url[8196];
|
||||||
short root_len;
|
short root_len;
|
||||||
char name[1024];
|
char name[1024];
|
||||||
|
char type[64];
|
||||||
} index_descriptor_t;
|
} index_descriptor_t;
|
||||||
|
|
||||||
typedef struct index_t {
|
typedef struct index_t {
|
||||||
|
|||||||
36
src/util.c
36
src/util.c
@@ -1,4 +1,5 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "src/ctx.h"
|
||||||
|
|
||||||
dyn_buffer_t dyn_buffer_create() {
|
dyn_buffer_t dyn_buffer_create() {
|
||||||
dyn_buffer_t buf;
|
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) {
|
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
|
__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) {
|
int text_buffer_append_char(text_buffer_t *buf, int c) {
|
||||||
|
|
||||||
if (SHOULD_IGNORE_CHAR(c)) {
|
if (SHOULD_IGNORE_CHAR(c) || c == ' ') {
|
||||||
if (!buf->last_char_was_whitespace) {
|
if (!buf->last_char_was_whitespace && buf->dyn_buffer.cur != 0) {
|
||||||
dyn_buffer_write_char(&buf->dyn_buffer, ' ');
|
dyn_buffer_write_char(&buf->dyn_buffer, ' ');
|
||||||
buf->last_char_was_whitespace = TRUE;
|
buf->last_char_was_whitespace = TRUE;
|
||||||
|
|
||||||
@@ -317,4 +322,29 @@ GHashTable *incremental_get_table() {
|
|||||||
return file_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#define INITIAL_BUF_SIZE 1024 * 16
|
#define INITIAL_BUF_SIZE 1024 * 16
|
||||||
|
|
||||||
#define SHOULD_IGNORE_CHAR(c) !(SHOULD_KEEP_CHAR(c))
|
#define SHOULD_IGNORE_CHAR(c) !(SHOULD_KEEP_CHAR(c))
|
||||||
#define SHOULD_KEEP_CHAR(c) ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'z') || (c > 127))
|
#define SHOULD_KEEP_CHAR(c) ((c >= '\'' && c <= ';') || (c >= 'A' && c <= 'z') || (c > 127))
|
||||||
|
|
||||||
|
|
||||||
typedef struct dyn_buffer {
|
typedef struct dyn_buffer {
|
||||||
@@ -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);
|
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
|
#endif
|
||||||
|
|||||||
117
src/web/serve.c
117
src/web/serve.c
@@ -110,7 +110,7 @@ int thumbnail(void *p, onion_request *req, onion_response *res) {
|
|||||||
int written = onion_response_write(res, data, data_len);
|
int written = onion_response_write(res, data, data_len);
|
||||||
onion_response_flush(res);
|
onion_response_flush(res);
|
||||||
if (written != data_len || data_len == 0) {
|
if (written != data_len || data_len == 0) {
|
||||||
printf("Couldn't write thumb\n");
|
LOG_DEBUG("serve.c", "Couldn't write thumbnail");
|
||||||
}
|
}
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
@@ -181,7 +181,12 @@ int chunked_response_file(const char *filename, const char *mime,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
onion_response_set_length(res, length);
|
onion_response_set_length(res, length);
|
||||||
onion_response_set_header(res, "Content-Type", mime);
|
if (mime != NULL) {
|
||||||
|
onion_response_set_header(res, "Content-Type", mime);
|
||||||
|
} else {
|
||||||
|
onion_response_set_header(res, "Content-Type", "application/octet-stream");
|
||||||
|
}
|
||||||
|
|
||||||
onion_response_write_headers(res);
|
onion_response_write_headers(res);
|
||||||
if ((onion_request_get_flags(request) & OR_HEAD) == OR_HEAD) {
|
if ((onion_request_get_flags(request) & OR_HEAD) == OR_HEAD) {
|
||||||
length = 0;
|
length = 0;
|
||||||
@@ -214,21 +219,13 @@ int chunked_response_file(const char *filename, const char *mime,
|
|||||||
return OCS_PROCESSED;
|
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);
|
int flags = onion_request_get_flags(req);
|
||||||
if ((flags & OR_METHODS) != OR_POST) {
|
if ((flags & OR_METHODS) != OR_POST) {
|
||||||
return OCS_NOT_PROCESSED;
|
return OCS_NOT_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *scroll_param;
|
|
||||||
const char *scroll = onion_request_get_query(req, "scroll");
|
|
||||||
if (scroll != NULL) {
|
|
||||||
scroll_param = "?scroll=3m";
|
|
||||||
} else {
|
|
||||||
scroll_param = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct onion_block_t *block = onion_request_get_data(req);
|
const struct onion_block_t *block = onion_request_get_data(req);
|
||||||
|
|
||||||
if (block == NULL) {
|
if (block == NULL) {
|
||||||
@@ -236,7 +233,7 @@ int search(void *p, onion_request *req, onion_response *res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char url[4096];
|
char url[4096];
|
||||||
snprintf(url, 4096, "%s/sist2/_search%s", WebCtx.es_url, scroll_param);
|
snprintf(url, 4096, "%s/sist2/_search", WebCtx.es_url);
|
||||||
response_t *r = web_post(url, onion_block_data(block), "Content-Type: application/json");
|
response_t *r = web_post(url, onion_block_data(block), "Content-Type: application/json");
|
||||||
|
|
||||||
set_default_headers(res);
|
set_default_headers(res);
|
||||||
@@ -254,43 +251,6 @@ int search(void *p, onion_request *req, onion_response *res) {
|
|||||||
return OCS_PROCESSED;
|
return OCS_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int scroll(void *p, onion_request *req, onion_response *res) {
|
|
||||||
|
|
||||||
int flags = onion_request_get_flags(req);
|
|
||||||
if ((flags & OR_METHODS) != OR_GET) {
|
|
||||||
return OCS_NOT_PROCESSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
char url[4096];
|
|
||||||
snprintf(url, 4096, "%s/_search/scroll", WebCtx.es_url);
|
|
||||||
|
|
||||||
const char *scroll_id = onion_request_get_query(req, "scroll_id");
|
|
||||||
|
|
||||||
cJSON *json = cJSON_CreateObject();
|
|
||||||
cJSON_AddStringToObject(json, "scroll_id", scroll_id);
|
|
||||||
cJSON_AddStringToObject(json, "scroll", "3m");
|
|
||||||
|
|
||||||
char *json_str = cJSON_PrintUnformatted(json);
|
|
||||||
response_t *r = web_post(url, json_str, "Content-Type: application/json");
|
|
||||||
|
|
||||||
cJSON_Delete(json);
|
|
||||||
cJSON_free(json_str);
|
|
||||||
|
|
||||||
if (r->status_code != 200) {
|
|
||||||
free_response(r);
|
|
||||||
return OCS_NOT_PROCESSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
set_default_headers(res);
|
|
||||||
onion_response_set_header(res, "Content-Type", "application/json");
|
|
||||||
onion_response_set_header(res, "Content-Disposition", "application/json");
|
|
||||||
onion_response_set_length(res, r->size);
|
|
||||||
onion_response_write(res, r->body, r->size);
|
|
||||||
free_response(r);
|
|
||||||
|
|
||||||
return OCS_PROCESSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
int serve_file_from_url(cJSON *json, index_t *idx, onion_request *req, onion_response *res) {
|
int serve_file_from_url(cJSON *json, index_t *idx, onion_request *req, onion_response *res) {
|
||||||
|
|
||||||
const char *path = cJSON_GetObjectItem(json, "path")->valuestring;
|
const char *path = cJSON_GetObjectItem(json, "path")->valuestring;
|
||||||
@@ -327,7 +287,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);
|
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 *json = cJSON_CreateObject();
|
||||||
cJSON *arr = cJSON_AddArrayToObject(json, "indices");
|
cJSON *arr = cJSON_AddArrayToObject(json, "indices");
|
||||||
|
|
||||||
@@ -353,14 +313,47 @@ int index_info(void *p, onion_request *req, onion_response *res) {
|
|||||||
return OCS_PROCESSED;
|
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");
|
const char *arg_uuid = onion_request_get_query(req, "1");
|
||||||
if (arg_uuid == NULL) {
|
if (arg_uuid == NULL) {
|
||||||
return OCS_PROCESSED;
|
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 *doc = NULL;
|
||||||
cJSON *index_id = NULL;
|
cJSON *index_id = NULL;
|
||||||
cJSON *source = NULL;
|
cJSON *source = NULL;
|
||||||
@@ -398,6 +391,23 @@ int file(void *p, onion_request *req, onion_response *res) {
|
|||||||
return ret;
|
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) {
|
void serve(const char *hostname, const char *port) {
|
||||||
onion *o = onion_new(O_POOL);
|
onion *o = onion_new(O_POOL);
|
||||||
onion_set_timeout(o, 3500);
|
onion_set_timeout(o, 3500);
|
||||||
@@ -416,7 +426,7 @@ void serve(const char *hostname, const char *port) {
|
|||||||
onion_url_add(urls, "img/sprite-skin-flat.png", img_sprite_skin_flag);
|
onion_url_add(urls, "img/sprite-skin-flat.png", img_sprite_skin_flag);
|
||||||
|
|
||||||
onion_url_add(urls, "es", search);
|
onion_url_add(urls, "es", search);
|
||||||
onion_url_add(urls, "scroll", scroll);
|
onion_url_add(urls, "status", status);
|
||||||
onion_url_add(
|
onion_url_add(
|
||||||
urls,
|
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})/"
|
"^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 +434,7 @@ void serve(const char *hostname, const char *port) {
|
|||||||
thumbnail
|
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, "^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);
|
onion_url_add(urls, "i", index_info);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -2,6 +2,26 @@
|
|||||||
outline: 0;
|
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 {
|
.path-row {
|
||||||
display: -ms-flexbox;
|
display: -ms-flexbox;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -32,7 +52,7 @@ body {
|
|||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card {
|
.card, .modal-content {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
background: #212121;
|
background: #212121;
|
||||||
color: #e0e0e0;
|
color: #e0e0e0;
|
||||||
@@ -40,6 +60,27 @@ body {
|
|||||||
border: none;
|
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 {
|
.sub-document {
|
||||||
background: #37474F !important;
|
background: #37474F !important;
|
||||||
}
|
}
|
||||||
@@ -134,6 +175,8 @@ body {
|
|||||||
|
|
||||||
.file-title {
|
.file-title {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
line-height: 1rem;
|
||||||
|
height: 1.1rem;
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -380,3 +423,21 @@ option {
|
|||||||
margin-top: -14px;
|
margin-top: -14px;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (min-width: 800px) {
|
||||||
|
.small-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.large-btn {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 801px) {
|
||||||
|
.small-btn {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
.large-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,25 @@
|
|||||||
outline: 0;
|
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 {
|
.path-row {
|
||||||
display: -ms-flexbox;
|
display: -ms-flexbox;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -100,6 +119,8 @@ body {
|
|||||||
|
|
||||||
.file-title {
|
.file-title {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
line-height: 1rem;
|
||||||
|
height: 1.1rem;
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -266,3 +287,21 @@ mark {
|
|||||||
margin-top: -14px;
|
margin-top: -14px;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (min-width: 800px) {
|
||||||
|
.small-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.large-btn {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 801px) {
|
||||||
|
.small-btn {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
.large-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
1
web/css/smartphoto.min.css
vendored
Normal file
1
web/css/smartphoto.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
102
web/js/dom.js
102
web/js/dom.js
@@ -75,6 +75,10 @@ function shouldPlayVideo(hit) {
|
|||||||
return videoc !== "hevc" && videoc !== "mpeg2video" && videoc !== "wmv3";
|
return videoc !== "hevc" && videoc !== "mpeg2video" && videoc !== "wmv3";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldDisplayRawImage(hit) {
|
||||||
|
return hit["_source"]["mime"] && hit["_source"]["mime"].startsWith("image/") && hit["_source"]["videoc"] !== "tiff";
|
||||||
|
}
|
||||||
|
|
||||||
function makePlaceholder(w, h, small) {
|
function makePlaceholder(w, h, small) {
|
||||||
let calc;
|
let calc;
|
||||||
if (small) {
|
if (small) {
|
||||||
@@ -96,10 +100,14 @@ function makePlaceholder(w, h, small) {
|
|||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ext(hit) {
|
||||||
|
return hit["_source"].hasOwnProperty("extension") && hit["_source"]["extension"] !== "" ? "." + hit["_source"]["extension"] : "";
|
||||||
|
}
|
||||||
|
|
||||||
function makeTitle(hit) {
|
function makeTitle(hit) {
|
||||||
let title = document.createElement("div");
|
let title = document.createElement("div");
|
||||||
title.setAttribute("class", "file-title");
|
title.setAttribute("class", "file-title");
|
||||||
let extension = hit["_source"].hasOwnProperty("extension") && hit["_source"]["extension"] !== "" ? "." + hit["_source"]["extension"] : "";
|
let extension = ext(hit);
|
||||||
|
|
||||||
applyNameToTitle(hit, title, extension);
|
applyNameToTitle(hit, title, extension);
|
||||||
|
|
||||||
@@ -113,7 +121,7 @@ function getTags(hit, mimeCategory) {
|
|||||||
switch (mimeCategory) {
|
switch (mimeCategory) {
|
||||||
case "video":
|
case "video":
|
||||||
case "image":
|
case "image":
|
||||||
if (hit["_source"].hasOwnProperty("videoc")) {
|
if (hit["_source"].hasOwnProperty("videoc") && hit["_source"]["videoc"]) {
|
||||||
const formatTag = document.createElement("span");
|
const formatTag = document.createElement("span");
|
||||||
formatTag.setAttribute("class", "badge badge-pill badge-video");
|
formatTag.setAttribute("class", "badge badge-pill badge-video");
|
||||||
formatTag.appendChild(document.createTextNode(hit["_source"]["videoc"].replace(" ", "")));
|
formatTag.appendChild(document.createTextNode(hit["_source"]["videoc"].replace(" ", "")));
|
||||||
@@ -121,7 +129,7 @@ function getTags(hit, mimeCategory) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "audio": {
|
case "audio": {
|
||||||
if (hit["_source"].hasOwnProperty("audioc")) {
|
if (hit["_source"].hasOwnProperty("audioc") && hit["_source"]["audioc"]) {
|
||||||
let formatTag = document.createElement("span");
|
let formatTag = document.createElement("span");
|
||||||
formatTag.setAttribute("class", "badge badge-pill badge-audio");
|
formatTag.setAttribute("class", "badge badge-pill badge-audio");
|
||||||
formatTag.appendChild(document.createTextNode(hit["_source"]["audioc"]));
|
formatTag.appendChild(document.createTextNode(hit["_source"]["audioc"]));
|
||||||
@@ -153,11 +161,44 @@ function getTags(hit, mimeCategory) {
|
|||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function infoButtonCb(hit) {
|
||||||
*
|
return () => {
|
||||||
* @param hit
|
getDocumentInfo(hit["_id"]).then(doc => {
|
||||||
* @returns {Element}
|
$("#modal-title").text(doc["name"] + ext(hit));
|
||||||
*/
|
|
||||||
|
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) || key.startsWith("exif_"))
|
||||||
|
.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) {
|
function createDocCard(hit) {
|
||||||
let docCard = document.createElement("div");
|
let docCard = document.createElement("div");
|
||||||
docCard.setAttribute("class", "card");
|
docCard.setAttribute("class", "card");
|
||||||
@@ -172,6 +213,7 @@ function createDocCard(hit) {
|
|||||||
let link = document.createElement("a");
|
let link = document.createElement("a");
|
||||||
link.setAttribute("href", "f/" + hit["_id"]);
|
link.setAttribute("href", "f/" + hit["_id"]);
|
||||||
link.setAttribute("target", "_blank");
|
link.setAttribute("target", "_blank");
|
||||||
|
link.style.maxWidth = "calc(100% - 1.2rem)";
|
||||||
link.appendChild(title);
|
link.appendChild(title);
|
||||||
|
|
||||||
if (hit["_source"].hasOwnProperty("parent")) {
|
if (hit["_source"].hasOwnProperty("parent")) {
|
||||||
@@ -271,7 +313,15 @@ function createDocCard(hit) {
|
|||||||
sizeTag.setAttribute("class", "text-muted");
|
sizeTag.setAttribute("class", "text-muted");
|
||||||
tagContainer.appendChild(sizeTag);
|
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);
|
docCard.appendChild(docCardBody);
|
||||||
|
|
||||||
docCardBody.appendChild(tagContainer);
|
docCardBody.appendChild(tagContainer);
|
||||||
@@ -337,6 +387,15 @@ function makeThumbnail(mimeCategory, hit, imgWrapper, small) {
|
|||||||
}
|
}
|
||||||
thumbnail.setAttribute("src", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
thumbnail.setAttribute("src", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
||||||
|
|
||||||
|
if (!hit["_source"]["parent"] && shouldDisplayRawImage(hit)) {
|
||||||
|
imgWrapper.setAttribute("id", "sp" + hit["_id"]);
|
||||||
|
imgWrapper.setAttribute("data-src", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
||||||
|
imgWrapper.setAttribute("href", `f/${hit["_id"]}`);
|
||||||
|
imgWrapper.setAttribute("data-caption", hit["_source"]["path"] + "/" + hit["_source"]["name"] + ext(hit));
|
||||||
|
imgWrapper.setAttribute("data-group", "p" + Math.floor(docCount / SIZE));
|
||||||
|
imgWrapper.classList.add("sp");
|
||||||
|
}
|
||||||
|
|
||||||
const placeholder = makePlaceholder(hit["_source"]["width"], hit["_source"]["height"], small);
|
const placeholder = makePlaceholder(hit["_source"]["width"], hit["_source"]["height"], small);
|
||||||
imgWrapper.appendChild(placeholder);
|
imgWrapper.appendChild(placeholder);
|
||||||
|
|
||||||
@@ -352,6 +411,14 @@ function makeThumbnail(mimeCategory, hit, imgWrapper, small) {
|
|||||||
return thumbnail;
|
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) {
|
function createDocLine(hit) {
|
||||||
|
|
||||||
const mime = hit["_source"]["mime"];
|
const mime = hit["_source"]["mime"];
|
||||||
@@ -372,6 +439,8 @@ function createDocLine(hit) {
|
|||||||
isSubDocument = true;
|
isSubDocument = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const infoButton = makeInfoButton(hit);
|
||||||
|
|
||||||
const title = makeTitle(hit);
|
const title = makeTitle(hit);
|
||||||
|
|
||||||
let link = document.createElement("a");
|
let link = document.createElement("a");
|
||||||
@@ -380,8 +449,13 @@ function createDocLine(hit) {
|
|||||||
link.appendChild(title);
|
link.appendChild(title);
|
||||||
|
|
||||||
const titleDiv = document.createElement("div");
|
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);
|
line.appendChild(media);
|
||||||
|
|
||||||
@@ -442,8 +516,7 @@ function makePreloader() {
|
|||||||
function makePageIndicator(searchResult) {
|
function makePageIndicator(searchResult) {
|
||||||
let pageIndicator = document.createElement("div");
|
let pageIndicator = document.createElement("div");
|
||||||
pageIndicator.setAttribute("class", "page-indicator font-weight-light");
|
pageIndicator.setAttribute("class", "page-indicator font-weight-light");
|
||||||
const totalHits = searchResult["hits"]["total"].hasOwnProperty("value")
|
const totalHits = searchResult["aggregations"]["total_count"]["value"];
|
||||||
? searchResult["hits"]["total"]["value"] : searchResult["hits"]["total"];
|
|
||||||
pageIndicator.appendChild(document.createTextNode(docCount + " / " + totalHits));
|
pageIndicator.appendChild(document.createTextNode(docCount + " / " + totalHits));
|
||||||
return pageIndicator;
|
return pageIndicator;
|
||||||
}
|
}
|
||||||
@@ -490,8 +563,7 @@ function makeStatsCard(searchResult) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let stat = document.createElement("span");
|
let stat = document.createElement("span");
|
||||||
const totalHits = searchResult["hits"]["total"].hasOwnProperty("value")
|
const totalHits = searchResult["aggregations"]["total_count"]["value"];
|
||||||
? searchResult["hits"]["total"]["value"] : searchResult["hits"]["total"];
|
|
||||||
stat.appendChild(document.createTextNode(totalHits + " results in " + searchResult["took"] + "ms"));
|
stat.appendChild(document.createTextNode(totalHits + " results in " + searchResult["took"] + "ms"));
|
||||||
|
|
||||||
statsCardBody.appendChild(stat);
|
statsCardBody.appendChild(stat);
|
||||||
|
|||||||
56
web/js/jquery-smartphoto.min.js
vendored
Normal file
56
web/js/jquery-smartphoto.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
129
web/js/search.js
129
web/js/search.js
@@ -6,7 +6,8 @@ let tagTree;
|
|||||||
|
|
||||||
let searchBar = document.getElementById("searchBar");
|
let searchBar = document.getElementById("searchBar");
|
||||||
let pathBar = document.getElementById("pathBar");
|
let pathBar = document.getElementById("pathBar");
|
||||||
let scroll_id = null;
|
let lastDoc = null;
|
||||||
|
let reachedEnd = false;
|
||||||
let docCount = 0;
|
let docCount = 0;
|
||||||
let coolingDown = false;
|
let coolingDown = false;
|
||||||
let searchBusy = true;
|
let searchBusy = true;
|
||||||
@@ -81,6 +82,13 @@ $.jsonPost("i").then(resp => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getDocumentInfo(id) {
|
||||||
|
return $.getJSON("d/" + id).fail(e => {
|
||||||
|
console.log(e);
|
||||||
|
showEsError();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function handleTreeClick(tree) {
|
function handleTreeClick(tree) {
|
||||||
return (event, node, handler) => {
|
return (event, node, handler) => {
|
||||||
event.preventTreeDefault();
|
event.preventTreeDefault();
|
||||||
@@ -144,8 +152,8 @@ $.jsonPost("es", {
|
|||||||
target: '#mimeTree'
|
target: '#mimeTree'
|
||||||
});
|
});
|
||||||
mimeTree.on("node.click", handleTreeClick(mimeTree));
|
mimeTree.on("node.click", handleTreeClick(mimeTree));
|
||||||
mimeTree.select();
|
mimeTree.deselect();
|
||||||
mimeTree.node("any").deselect();
|
mimeTree.node("any").select();
|
||||||
});
|
});
|
||||||
|
|
||||||
function leafTag(tag) {
|
function leafTag(tag) {
|
||||||
@@ -252,41 +260,18 @@ function insertHits(resultContainer, hits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("scroll", function () {
|
window.addEventListener("scroll", function () {
|
||||||
if (!coolingDown && !searchBusy) {
|
if (!searchBusy) {
|
||||||
let threshold = 400;
|
let threshold = 400;
|
||||||
|
|
||||||
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight - threshold) {
|
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight - threshold) {
|
||||||
coolingDown = true;
|
if (!reachedEnd) {
|
||||||
doScroll();
|
coolingDown = true;
|
||||||
|
search(lastDoc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function doScroll() {
|
|
||||||
$.get("scroll", {scroll_id: scroll_id})
|
|
||||||
.then(searchResult => {
|
|
||||||
let searchResults = document.getElementById("searchResults");
|
|
||||||
let hits = searchResult["hits"]["hits"];
|
|
||||||
|
|
||||||
//Page indicator
|
|
||||||
let pageIndicator = makePageIndicator(searchResult);
|
|
||||||
searchResults.appendChild(pageIndicator);
|
|
||||||
|
|
||||||
//Result container
|
|
||||||
let resultContainer = makeResultContainer();
|
|
||||||
searchResults.appendChild(resultContainer);
|
|
||||||
|
|
||||||
insertHits(resultContainer, hits);
|
|
||||||
|
|
||||||
if (hits.length === SIZE) {
|
|
||||||
coolingDown = false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.fail(() => {
|
|
||||||
window.location.reload();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSelectedNodes(tree) {
|
function getSelectedNodes(tree) {
|
||||||
let selectedNodes = [];
|
let selectedNodes = [];
|
||||||
|
|
||||||
@@ -307,21 +292,25 @@ function getSelectedNodes(tree) {
|
|||||||
return selectedNodes
|
return selectedNodes
|
||||||
}
|
}
|
||||||
|
|
||||||
function search() {
|
function search(after = null) {
|
||||||
|
lastDoc = null;
|
||||||
|
|
||||||
if (searchBusy) {
|
if (searchBusy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
searchBusy = true;
|
searchBusy = true;
|
||||||
|
|
||||||
//Clear old search results
|
|
||||||
let searchResults = document.getElementById("searchResults");
|
let searchResults = document.getElementById("searchResults");
|
||||||
while (searchResults.firstChild) {
|
//Clear old search results
|
||||||
searchResults.removeChild(searchResults.firstChild);
|
let preload;
|
||||||
|
if (!after) {
|
||||||
|
while (searchResults.firstChild) {
|
||||||
|
searchResults.removeChild(searchResults.firstChild);
|
||||||
|
}
|
||||||
|
preload = makePreloader();
|
||||||
|
searchResults.appendChild(preload);
|
||||||
}
|
}
|
||||||
|
|
||||||
const preload = makePreloader();
|
|
||||||
searchResults.appendChild(preload);
|
|
||||||
|
|
||||||
let query = searchBar.value;
|
let query = searchBar.value;
|
||||||
let empty = query === "";
|
let empty = query === "";
|
||||||
let condition = empty ? "should" : "must";
|
let condition = empty ? "should" : "must";
|
||||||
@@ -355,25 +344,25 @@ function search() {
|
|||||||
filters.push([{terms: {"tag": tags}}]);
|
filters.push([{terms: {"tag": tags}}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$.jsonPost("es?scroll=1", {
|
let q = {
|
||||||
"_source": {
|
"_source": {
|
||||||
excludes: ["content"]
|
excludes: ["content", "_tie"]
|
||||||
},
|
},
|
||||||
query: {
|
query: {
|
||||||
bool: {
|
bool: {
|
||||||
[condition]: {
|
[condition]: {
|
||||||
multi_match: {
|
simple_query_string: {
|
||||||
query: query,
|
query: query,
|
||||||
type: "most_fields",
|
|
||||||
fields: fields,
|
fields: fields,
|
||||||
operator: "and"
|
default_operator: "and"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
filter: filters
|
filter: filters
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sort: [
|
"sort": [
|
||||||
"_score"
|
{"_score": {"order": "desc"}},
|
||||||
|
{"_tie": {"order": "asc"}}
|
||||||
],
|
],
|
||||||
highlight: {
|
highlight: {
|
||||||
pre_tags: ["<mark>"],
|
pre_tags: ["<mark>"],
|
||||||
@@ -386,24 +375,45 @@ function search() {
|
|||||||
font_name: {},
|
font_name: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
aggs: {
|
aggs:
|
||||||
total_size: {"sum": {"field": "size"}}
|
{
|
||||||
},
|
total_size: {"sum": {"field": "size"}},
|
||||||
|
total_count: {"value_count": {"field": "size"}}
|
||||||
|
},
|
||||||
size: SIZE,
|
size: SIZE,
|
||||||
}).then(searchResult => {
|
};
|
||||||
scroll_id = searchResult["_scroll_id"];
|
|
||||||
|
|
||||||
preload.remove();
|
if (after) {
|
||||||
//Search stats
|
q.search_after = [after["_score"], after["_id"]];
|
||||||
searchResults.appendChild(makeStatsCard(searchResult));
|
}
|
||||||
|
|
||||||
|
$.jsonPost("es", q).then(searchResult => {
|
||||||
|
let hits = searchResult["hits"]["hits"];
|
||||||
|
if (hits) {
|
||||||
|
lastDoc = hits[hits.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!after) {
|
||||||
|
preload.remove();
|
||||||
|
searchResults.appendChild(makeStatsCard(searchResult));
|
||||||
|
} else {
|
||||||
|
let pageIndicator = makePageIndicator(searchResult);
|
||||||
|
searchResults.appendChild(pageIndicator);
|
||||||
|
}
|
||||||
|
|
||||||
//Setup page
|
//Setup page
|
||||||
let resultContainer = makeResultContainer();
|
let resultContainer = makeResultContainer();
|
||||||
searchResults.appendChild(resultContainer);
|
searchResults.appendChild(resultContainer);
|
||||||
|
|
||||||
docCount = 0;
|
window.setTimeout(() => {
|
||||||
insertHits(resultContainer, searchResult["hits"]["hits"]);
|
$(".sp").SmartPhoto({animationSpeed: 0, swipeTopToClose: true, showAnimation: false, forceInterval: 50});
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
if (!after) {
|
||||||
|
docCount = 0;
|
||||||
|
}
|
||||||
|
reachedEnd = hits.length !== SIZE;
|
||||||
|
insertHits(resultContainer, hits);
|
||||||
searchBusy = false;
|
searchBusy = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -464,6 +474,15 @@ function updateIndices() {
|
|||||||
document.getElementById("indices").addEventListener("change", updateIndices);
|
document.getElementById("indices").addEventListener("change", updateIndices);
|
||||||
updateIndices();
|
updateIndices();
|
||||||
|
|
||||||
|
window.onkeyup = function(e) {
|
||||||
|
if (e.key === "/" || e.key === "Escape") {
|
||||||
|
const bar = document.getElementById("searchBar");
|
||||||
|
bar.scrollIntoView();
|
||||||
|
bar.focus();
|
||||||
|
}
|
||||||
|
console.log(e)
|
||||||
|
};
|
||||||
|
|
||||||
//Suggest
|
//Suggest
|
||||||
function getPathChoices() {
|
function getPathChoices() {
|
||||||
return new Promise(getPaths => {
|
return new Promise(getPaths => {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<nav class="navbar navbar-expand-lg">
|
<nav class="navbar navbar-expand-lg">
|
||||||
<a class="navbar-brand" href="/">sist2</a>
|
<a class="navbar-brand" href="/">sist2</a>
|
||||||
<span class="badge badge-pill version">v1.2.0</span>
|
<span class="badge badge-pill version">v1.2.13</span>
|
||||||
<span class="tagline">Lightning-fast file system indexer and search tool </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>
|
<a style="margin-left: auto" id="theme" class="btn" title="Toggle theme" href="/">Theme</a>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -25,13 +25,20 @@
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<div class="input-group-text">
|
<div class="input-group-text">
|
||||||
<span title="Toggle fuzzy searching" onclick="document.getElementById('fuzzyToggle').click()">Fuzzy </span>
|
<span title="Toggle fuzzy searching" onclick="document.getElementById('fuzzyToggle').click()">Fuzzy </span>
|
||||||
<input title="Toggle fuzzy searching" type="checkbox" id="fuzzyToggle"
|
<input title="Toggle fuzzy searching" type="checkbox" id="fuzzyToggle"
|
||||||
onclick="toggleFuzzy()" checked>
|
onclick="toggleFuzzy()" checked>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input id="searchBar" type="search" class="form-control" placeholder="Search">
|
<input id="searchBar" type="search" class="form-control" placeholder="Search">
|
||||||
|
<div class="input-group-append">
|
||||||
|
<button class="btn btn-outline-secondary small-btn" type="button" data-toggle="modal"
|
||||||
|
data-target="#help">?
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-outline-secondary large-btn" type="button" data-toggle="modal"
|
||||||
|
data-target="#help">Help
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input title="File size" id="sizeSlider" name="size">
|
<input title="File size" id="sizeSlider" name="size">
|
||||||
@@ -45,10 +52,12 @@
|
|||||||
<div class="col" id="treeTabs">
|
<div class="col" id="treeTabs">
|
||||||
<ul class="nav nav-tabs" role="tablist">
|
<ul class="nav nav-tabs" role="tablist">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" data-toggle="tab" href="#mime" role="tab" aria-controls="home" aria-selected="true">Mime Types</a>
|
<a class="nav-link active" data-toggle="tab" href="#mime" role="tab" aria-controls="home"
|
||||||
|
aria-selected="true">Mime Types</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" data-toggle="tab" href="#tag" role="tab" aria-controls="profile" aria-selected="false" title="User-defined tags">Tags</a>
|
<a class="nav-link" data-toggle="tab" href="#tag" role="tab" aria-controls="profile"
|
||||||
|
aria-selected="false" title="User-defined tags">Tags</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content" id="myTabContent">
|
<div class="tab-content" id="myTabContent">
|
||||||
@@ -65,6 +74,83 @@
|
|||||||
</div>
|
</div>
|
||||||
</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 class="modal" id="help" 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">Search help</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td><code>+</code></td>
|
||||||
|
<td>signifies AND operation</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>|</code></td>
|
||||||
|
<td>signifies OR operation</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>-</code></td>
|
||||||
|
<td>negates a single token</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>""</code></td>
|
||||||
|
<td>wraps a number of tokens to signify a phrase for searching</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>*</code></td>
|
||||||
|
<td>at the end of a term signifies a prefix query</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>(</code> and <code>)</code></td>
|
||||||
|
<td>signify precedence</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>~N</code></td>
|
||||||
|
<td>after a word signifies edit distance (fuzziness)</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>~N</code></td>
|
||||||
|
<td>after a phrase signifies slop amount</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>For example: <code>"fried eggs" +(eggplant | potato) -frittata</code> will match the phrase
|
||||||
|
<i>fried eggs</i> and either <i>eggplant</i> or <i>potato</i>, but will ignore results
|
||||||
|
containing <i>frittata</i>.</p>
|
||||||
|
|
||||||
|
<p>When neither <code>+</code> or <code>|</code> is specified, the default operator is <code>+</code> (and).</p>
|
||||||
|
<p>When the <b>Fuzzy</b> option is checked, partial matches are also returned.</p>
|
||||||
|
<br>
|
||||||
|
<p>For more information, see <a target="_blank"
|
||||||
|
href="//www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html">Elasticsearch
|
||||||
|
documentation</a></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="searchResults"></div>
|
<div id="searchResults"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user