mirror of
https://github.com/simon987/sist2.git
synced 2025-12-13 15:29:04 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 919f45c79c | |||
| d42129cfcb | |||
| 754983e34a | |||
| 7c8a3e2f9d | |||
| 3bb24b4453 | |||
| 9a56b959d3 | |||
| 5e3a2dbcc2 | |||
| 573f94f24e | |||
| f5db78a69f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,3 +15,4 @@ bundle*.css
|
|||||||
bundle.js
|
bundle.js
|
||||||
*.a
|
*.a
|
||||||
vgcore.*
|
vgcore.*
|
||||||
|
build/
|
||||||
|
|||||||
21
.gitmodules
vendored
21
.gitmodules
vendored
@@ -31,15 +31,12 @@
|
|||||||
[submodule "lib/mupdf"]
|
[submodule "lib/mupdf"]
|
||||||
path = lib/mupdf
|
path = lib/mupdf
|
||||||
url = git://git.ghostscript.com/mupdf.git
|
url = git://git.ghostscript.com/mupdf.git
|
||||||
[submodule "lib/zstd"]
|
[submodule "lib/tesseract"]
|
||||||
path = lib/zstd
|
path = lib/tesseract
|
||||||
url = https://github.com/facebook/zstd
|
url = https://github.com/tesseract-ocr/tesseract
|
||||||
[submodule "lib/lz4"]
|
[submodule "lib/leptonica"]
|
||||||
path = lib/lz4
|
path = lib/leptonica
|
||||||
url = https://github.com/lz4/lz4
|
url = https://github.com/danbloomberg/leptonica
|
||||||
[submodule "lib/libarchive"]
|
[submodule "lib/libtiff"]
|
||||||
path = lib/libarchive
|
path = lib/libtiff
|
||||||
url = https://github.com/libarchive/libarchive
|
url = https://gitlab.com/libtiff/libtiff
|
||||||
[submodule "lib/libxml2"]
|
|
||||||
path = lib/libxml2
|
|
||||||
url = https://github.com/GNOME/libxml2
|
|
||||||
|
|||||||
135
CMakeLists.txt
135
CMakeLists.txt
@@ -1,13 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.7)
|
cmake_minimum_required(VERSION 3.7)
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
|
||||||
option(WITH_SIST2 "Build main executable" ON)
|
|
||||||
option(WITH_SIST2_SCAN "Build scan executable" ON)
|
|
||||||
|
|
||||||
project(sist2 C)
|
project(sist2 C)
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeModules")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeModules")
|
||||||
|
|
||||||
if (WITH_SIST2)
|
|
||||||
add_executable(
|
add_executable(
|
||||||
sist2
|
sist2
|
||||||
src/main.c
|
src/main.c
|
||||||
@@ -45,43 +41,6 @@ if (WITH_SIST2)
|
|||||||
# utf8.h
|
# utf8.h
|
||||||
utf8.h/utf8.h
|
utf8.h/utf8.h
|
||||||
)
|
)
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (WITH_SIST2_SCAN)
|
|
||||||
add_executable(
|
|
||||||
sist2_scan
|
|
||||||
src/main.c
|
|
||||||
src/sist.h
|
|
||||||
src/io/walk.h src/io/walk.c
|
|
||||||
src/parsing/media.h src/parsing/media.c
|
|
||||||
src/parsing/pdf.h src/parsing/pdf.c
|
|
||||||
src/io/store.h src/io/store.c
|
|
||||||
src/tpool.h src/tpool.c
|
|
||||||
src/parsing/parse.h src/parsing/parse.c
|
|
||||||
src/io/serialize.h src/io/serialize.c
|
|
||||||
src/parsing/mime.h src/parsing/mime.c src/parsing/mime_generated.c
|
|
||||||
src/parsing/text.h src/parsing/text.c
|
|
||||||
src/util.c src/util.h
|
|
||||||
src/ctx.h src/types.h src/parsing/font.c src/parsing/font.h
|
|
||||||
src/parsing/arc.h src/parsing/arc.c
|
|
||||||
src/parsing/doc.h src/parsing/doc.c
|
|
||||||
src/log.h src/log.c
|
|
||||||
|
|
||||||
# argparse
|
|
||||||
argparse/argparse.h argparse/argparse.c
|
|
||||||
|
|
||||||
# cJSON
|
|
||||||
cJSON/cJSON.h cJSON/cJSON.c
|
|
||||||
|
|
||||||
# LMDB
|
|
||||||
lmdb/libraries/liblmdb/lmdb.h lmdb/libraries/liblmdb/mdb.c
|
|
||||||
lmdb/libraries/liblmdb/midl.h lmdb/libraries/liblmdb/midl.c
|
|
||||||
src/cli.c src/cli.h
|
|
||||||
|
|
||||||
# utf8.h
|
|
||||||
utf8.h/utf8.h
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
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/")
|
||||||
@@ -102,7 +61,6 @@ list(REMOVE_ITEM GLIB_LIBRARIES pcre)
|
|||||||
list(REMOVE_ITEM GOBJECT_LIBRARIES pcre)
|
list(REMOVE_ITEM GOBJECT_LIBRARIES pcre)
|
||||||
list(REMOVE_ITEM UUID_LIBRARIES pcre)
|
list(REMOVE_ITEM UUID_LIBRARIES pcre)
|
||||||
|
|
||||||
if (WITH_SIST2)
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
sist2 PUBLIC
|
sist2 PUBLIC
|
||||||
${GOBJECT_INCLUDE_DIRS}
|
${GOBJECT_INCLUDE_DIRS}
|
||||||
@@ -116,13 +74,13 @@ if (WITH_SIST2)
|
|||||||
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
||||||
${PROJECT_SOURCE_DIR}/include/
|
${PROJECT_SOURCE_DIR}/include/
|
||||||
/usr/include/libxml2/
|
/usr/include/libxml2/
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/tesseract/include/
|
||||||
)
|
)
|
||||||
target_link_directories(
|
target_link_directories(
|
||||||
sist2 PUBLIC
|
sist2 PUBLIC
|
||||||
${UUID_LIBRARY_DIRS}
|
${UUID_LIBRARY_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
target_compile_options(sist2
|
target_compile_options(sist2
|
||||||
PRIVATE
|
PRIVATE
|
||||||
-Ofast
|
-Ofast
|
||||||
@@ -162,100 +120,21 @@ if (WITH_SIST2)
|
|||||||
freetype
|
freetype
|
||||||
archive
|
archive
|
||||||
|
|
||||||
# ${PROJECT_SOURCE_DIR}/lib/libxml2.a
|
|
||||||
xml2
|
xml2
|
||||||
${PROJECT_SOURCE_DIR}/lib/libopc/libmce.a
|
${PROJECT_SOURCE_DIR}/lib/libopc/libmce.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libopc/libopc.a
|
${PROJECT_SOURCE_DIR}/lib/libopc/libopc.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libopc/libplib.a
|
${PROJECT_SOURCE_DIR}/lib/libopc/libplib.a
|
||||||
|
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libtesseract.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/liblept.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libtiff.a
|
||||||
|
png
|
||||||
|
stdc++
|
||||||
)
|
)
|
||||||
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (WITH_SIST2_SCAN)
|
|
||||||
|
|
||||||
set_target_properties(
|
|
||||||
sist2_scan
|
|
||||||
PROPERTIES COMPILE_DEFINITIONS SIST_SCAN_ONLY
|
|
||||||
)
|
|
||||||
set_target_properties(
|
|
||||||
sist2_scan
|
|
||||||
PROPERTIES
|
|
||||||
COMPILE_DEFINITIONS SIST_SCAN_ONLY
|
|
||||||
LINK_FLAGS -static
|
|
||||||
)
|
|
||||||
target_include_directories(
|
|
||||||
sist2_scan PUBLIC
|
|
||||||
${LIBMAGIC_INCLUDE_DIRS}
|
|
||||||
${GOBJECT_INCLUDE_DIRS}
|
|
||||||
${OPENSSL_INCLUDE_DIR}
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/ffmpeg/
|
|
||||||
${GLIB_INCLUDE_DIRS}
|
|
||||||
${UUID_INCLUDE_DIRS}
|
|
||||||
${FREETYPE_INCLUDE_DIRS}
|
|
||||||
${PROJECT_SOURCE_DIR}/
|
|
||||||
${PROJECT_SOURCE_DIR}/lmdb/libraries/liblmdb/
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/onion/src/
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
|
||||||
${PROJECT_SOURCE_DIR}/include/
|
|
||||||
/usr/include/libxml2/
|
|
||||||
)
|
|
||||||
target_link_directories(
|
|
||||||
sist2_scan PUBLIC
|
|
||||||
${UUID_LIBRARY_DIRS}
|
|
||||||
)
|
|
||||||
target_compile_options(sist2_scan
|
|
||||||
PRIVATE
|
|
||||||
-Ofast
|
|
||||||
# -march=native
|
|
||||||
-fno-stack-protector
|
|
||||||
-fomit-frame-pointer
|
|
||||||
)
|
|
||||||
TARGET_LINK_LIBRARIES(
|
|
||||||
sist2_scan
|
|
||||||
|
|
||||||
${GLIB_LIBRARIES}
|
|
||||||
${GOBJECT_LIBRARIES}
|
|
||||||
${UUID_LIBRARIES}
|
|
||||||
|
|
||||||
# ffmpeg
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavcodec.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavformat.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavutil.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libswscale.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libswresample.a
|
|
||||||
|
|
||||||
# mupdf
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmupdf.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmupdf-third.a
|
|
||||||
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libbz2.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmagic.a
|
|
||||||
|
|
||||||
pthread
|
|
||||||
m
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libharfbuzz.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libopenjp2.a
|
|
||||||
freetype
|
|
||||||
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libarchive.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/liblz4.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/liblzma.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libzstd.a
|
|
||||||
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libxml2.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libopc/libmce.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libopc/libopc.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libopc/libplib.a
|
|
||||||
)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
before_sist2
|
before_sist2
|
||||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/before_build.sh
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/before_build.sh
|
||||||
)
|
)
|
||||||
|
|
||||||
IF (WITH_SIST2)
|
|
||||||
add_dependencies(sist2 before_sist2)
|
add_dependencies(sist2 before_sist2)
|
||||||
else ()
|
|
||||||
add_dependencies(sist2_scan before_sist2)
|
|
||||||
endif ()
|
|
||||||
|
|||||||
@@ -2,7 +2,17 @@ FROM ubuntu:19.10
|
|||||||
MAINTAINER simon987 <me@simon987.net>
|
MAINTAINER simon987 <me@simon987.net>
|
||||||
|
|
||||||
RUN apt update
|
RUN apt update
|
||||||
RUN apt install -y libglib2.0-0 libcurl4 libmagic1 libharfbuzz-bin libopenjp2-7 libarchive13 liblzma5 libzstd1 liblz4-1
|
RUN apt install -y libglib2.0-0 libcurl4 libmagic1 libharfbuzz-bin libopenjp2-7 libarchive13 liblzma5 libzstd1 liblz4-1 \
|
||||||
|
curl libtiff5 libpng16-16
|
||||||
|
|
||||||
|
RUN mkdir -p /usr/share/tessdata && \
|
||||||
|
cd /usr/share/tessdata/ && \
|
||||||
|
curl -o /usr/share/tessdata/hin.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/hin.traineddata &&\
|
||||||
|
curl -o /usr/share/tessdata/jpn.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/jpn.traineddata &&\
|
||||||
|
curl -o /usr/share/tessdata/eng.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/eng.traineddata &&\
|
||||||
|
curl -o /usr/share/tessdata/fra.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/fra.traineddata &&\
|
||||||
|
curl -o /usr/share/tessdata/rus.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/rus.traineddata &&\
|
||||||
|
curl -o /usr/share/tessdata/spa.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata/master/spa.traineddata && ls -lh
|
||||||
|
|
||||||
ADD sist2 /root/sist2
|
ADD sist2 /root/sist2
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
rm ./sist2
|
rm ./sist2
|
||||||
cp ../sist2 .
|
cp ../sist2 .
|
||||||
|
strip sist2
|
||||||
|
|
||||||
version=$(./sist2 --version)
|
version=$(./sist2 --version)
|
||||||
|
|
||||||
|
|||||||
30
README.md
30
README.md
@@ -1,5 +1,6 @@
|
|||||||

|

|
||||||
[](https://www.codefactor.io/repository/github/simon987/sist2)
|
[](https://www.codefactor.io/repository/github/simon987/sist2)
|
||||||
|
[/statusIcon)](https://files.simon987.net/artifacts/Sist2/Build/)
|
||||||
|
|
||||||
# sist2
|
# sist2
|
||||||
|
|
||||||
@@ -16,16 +17,19 @@ sist2 (Simple incremental search tool)
|
|||||||
* Incremental scanning
|
* Incremental scanning
|
||||||
* Automatic tagging from file attributes via [user scripts](scripting/README.md)
|
* Automatic tagging from file attributes via [user scripts](scripting/README.md)
|
||||||
* Recursive scan inside archive files \*\*
|
* Recursive scan inside archive files \*\*
|
||||||
|
* OCR support with tesseract \*\*\*
|
||||||
|
|
||||||
|
|
||||||
\* See [format support](#format-support)
|
\* See [format support](#format-support)
|
||||||
\** See [Archive files](#archive-files)
|
\*\* See [Archive files](#archive-files)
|
||||||
|
\*\*\* See [OCR](#ocr)
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
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)* `docker pull simon987/sist2:latest`
|
1. *(or)* `docker pull simon987/sist2:latest`
|
||||||
|
|
||||||
|
|
||||||
@@ -85,7 +89,7 @@ docker stop sist2
|
|||||||
|
|
||||||
File type | Library | Content | Thumbnail | Metadata
|
File type | Library | Content | Thumbnail | Metadata
|
||||||
:---|:---|:---|:---|:---
|
:---|:---|:---|:---|:---
|
||||||
pdf,xps,cbz,fb2,epub | MuPDF | yes | 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` | `EXIF:Artist`, `EXIF:ImageDescription` |
|
||||||
@@ -111,6 +115,21 @@ scan is also supported.
|
|||||||
To check if a media file can be parsed without *seek*, execute `cat file.mp4 | ffprobe -`
|
To check if a media file can be parsed without *seek*, execute `cat file.mp4 | ffprobe -`
|
||||||
|
|
||||||
|
|
||||||
|
### OCR
|
||||||
|
|
||||||
|
You can enable OCR support for pdf,xps,cbz,fb2,epub file types with the
|
||||||
|
`--ocr <lang>` option. Download the language data files with your
|
||||||
|
package manager (`apt install tesseract-ocr-eng`) or directly [from Github](https://github.com/tesseract-ocr/tesseract/wiki/Data-Files).
|
||||||
|
|
||||||
|
The `simon987/sist2` github image comes with common languages
|
||||||
|
(hin, jpn, eng, fra, rus, spa) pre-installed.
|
||||||
|
|
||||||
|
Examples
|
||||||
|
```bash
|
||||||
|
sist2 scan --ocr jpn ~/Books/Manga/
|
||||||
|
sist2 scan --ocr eng ~/Books/Textbooks/
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Build from source
|
## Build from source
|
||||||
|
|
||||||
@@ -124,12 +143,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
|
libarchive-dev libtiff5 libpng16-16 libpango1.0-dev
|
||||||
```
|
|
||||||
*(FreeBSD)*
|
|
||||||
```bash
|
|
||||||
pkg install cmake gcc yasm gmake bash ffmpeg e2fsprogs-uuid\
|
|
||||||
autotools ragel libarchive
|
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Build
|
2. Build
|
||||||
|
|||||||
1
lib/leptonica
Submodule
1
lib/leptonica
Submodule
Submodule lib/leptonica added at cc03be70fd
Submodule lib/libarchive deleted from 6f4fceb714
1
lib/libtiff
Submodule
1
lib/libtiff
Submodule
Submodule lib/libtiff added at 3db0ff91bc
Submodule lib/libxml2 deleted from 0815302dee
1
lib/lz4
1
lib/lz4
Submodule lib/lz4 deleted from 0f749838bf
1
lib/tesseract
Submodule
1
lib/tesseract
Submodule
Submodule lib/tesseract added at f268e6615e
1
lib/zstd
1
lib/zstd
Submodule lib/zstd deleted from d73e2fb465
@@ -13,19 +13,24 @@
|
|||||||
"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 +75,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",
|
||||||
|
|||||||
@@ -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 .
|
||||||
@@ -33,7 +33,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 ..
|
||||||
|
|
||||||
@@ -70,43 +71,30 @@ make -j $THREADS
|
|||||||
cd ..
|
cd ..
|
||||||
mv libmagic/src/.libs/libmagic.a .
|
mv libmagic/src/.libs/libmagic.a .
|
||||||
|
|
||||||
# libarchive
|
# tesseract
|
||||||
cd libarchive/build
|
cd tesseract
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake -DSTATIC=on -DBUILD_TRAINING_TOOLS=off ..
|
||||||
|
make -j $THREADS
|
||||||
|
cd ../..
|
||||||
|
mv tesseract/build/libtesseract.a .
|
||||||
|
|
||||||
|
# leptonica
|
||||||
|
cd leptonica
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
cd ..
|
./configure --without-zlib --without-jpeg --without-giflib \
|
||||||
./configure --without-nettle --without-expat --without-xml2 --without-openssl
|
--without-giflib --without-libwebp --without-libwebpmux --without-libopenjpeg \
|
||||||
|
--enable-static --disable-shared
|
||||||
make -j $THREADS
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv libarchive/.libs/libarchive.a .
|
mv leptonica/src/.libs/liblept.a .
|
||||||
|
|
||||||
# lz4
|
# tiff
|
||||||
cd lz4
|
cd libtiff
|
||||||
make -j $THREADS
|
|
||||||
cd ..
|
|
||||||
mv lz4/lib/liblz4.a .
|
|
||||||
|
|
||||||
# lzma
|
|
||||||
wget https://newcontinuum.dl.sourceforge.net/project/lzmautils/xz-5.2.3.tar.gz
|
|
||||||
tar -xzf xz-5.2.3.tar.gz
|
|
||||||
rm xz-5.2.3.tar.gz
|
|
||||||
cd xz-5.2.3
|
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure
|
./configure --enable-static --disable-shared --disable-lzw --disable-jpeg --disable-webp \
|
||||||
|
--disable-lzma --disable-zstd --disable-jbig
|
||||||
make -j $THREADS
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv xz-5.2.3/src/liblzma/.libs/liblzma.a .
|
mv libtiff/libtiff/.libs/libtiff.a .
|
||||||
|
|
||||||
# zstd
|
|
||||||
cd zstd
|
|
||||||
make -j $THREADS
|
|
||||||
cd ..
|
|
||||||
mv zstd/lib/libzstd.a .
|
|
||||||
|
|
||||||
# xml2
|
|
||||||
cd libxml2
|
|
||||||
./autogen.sh --without-zlib --without-lzma
|
|
||||||
make
|
|
||||||
cd ..
|
|
||||||
mv libxml2/.libs/libxml2.a .
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
@@ -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 ..
|
|
||||||
26
src/cli.c
26
src/cli.c
@@ -1,6 +1,8 @@
|
|||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
#include "ctx.h"
|
#include "ctx.h"
|
||||||
|
|
||||||
|
#include <tesseract/capi.h>
|
||||||
|
|
||||||
#define DEFAULT_OUTPUT "index.sist2/"
|
#define DEFAULT_OUTPUT "index.sist2/"
|
||||||
#define DEFAULT_CONTENT_SIZE 32768
|
#define DEFAULT_CONTENT_SIZE 32768
|
||||||
#define DEFAULT_QUALITY 5
|
#define DEFAULT_QUALITY 5
|
||||||
@@ -35,8 +37,6 @@ void scan_args_destroy(scan_args_t *args) {
|
|||||||
free(args);
|
free(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
|
|
||||||
void index_args_destroy(index_args_t *args) {
|
void index_args_destroy(index_args_t *args) {
|
||||||
//todo
|
//todo
|
||||||
free(args);
|
free(args);
|
||||||
@@ -47,8 +47,6 @@ void web_args_destroy(web_args_t *args) {
|
|||||||
free(args);
|
free(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "Required positional argument: PATH.\n");
|
fprintf(stderr, "Required positional argument: PATH.\n");
|
||||||
@@ -136,6 +134,17 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->tesseract_lang != NULL) {
|
||||||
|
TessBaseAPI *api = TessBaseAPICreate();
|
||||||
|
ret = TessBaseAPIInit3(api, TESS_DATAPATH, args->tesseract_lang);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "Could not initialize tesseract with lang '%s'\n", args->tesseract_lang);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
TessBaseAPIEnd(api);
|
||||||
|
TessBaseAPIDelete(api);
|
||||||
|
}
|
||||||
|
|
||||||
LOG_DEBUGF("cli.c", "arg quality=%f", args->quality)
|
LOG_DEBUGF("cli.c", "arg quality=%f", args->quality)
|
||||||
LOG_DEBUGF("cli.c", "arg size=%d", args->size)
|
LOG_DEBUGF("cli.c", "arg size=%d", args->size)
|
||||||
LOG_DEBUGF("cli.c", "arg content_size=%d", args->content_size)
|
LOG_DEBUGF("cli.c", "arg content_size=%d", args->content_size)
|
||||||
@@ -147,14 +156,15 @@ 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)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -216,6 +226,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;
|
||||||
@@ -273,5 +285,3 @@ web_args_t *web_args_create() {
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ typedef struct scan_args {
|
|||||||
char *path;
|
char *path;
|
||||||
char *archive;
|
char *archive;
|
||||||
archive_mode_t archive_mode;
|
archive_mode_t archive_mode;
|
||||||
|
char *tesseract_lang;
|
||||||
} scan_args_t;
|
} scan_args_t;
|
||||||
|
|
||||||
scan_args_t *scan_args_create();
|
scan_args_t *scan_args_create();
|
||||||
void scan_args_destroy(scan_args_t *args);
|
void scan_args_destroy(scan_args_t *args);
|
||||||
int scan_args_validate(scan_args_t *args, int argc, const char **argv);
|
int scan_args_validate(scan_args_t *args, int argc, const char **argv);
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
typedef struct index_args {
|
typedef struct index_args {
|
||||||
char *es_url;
|
char *es_url;
|
||||||
const char *index_path;
|
const char *index_path;
|
||||||
@@ -51,6 +51,5 @@ void web_args_destroy(web_args_t *args);
|
|||||||
|
|
||||||
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);
|
||||||
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);
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ struct {
|
|||||||
GHashTable *copy_table;
|
GHashTable *copy_table;
|
||||||
|
|
||||||
pthread_mutex_t mupdf_mu;
|
pthread_mutex_t mupdf_mu;
|
||||||
|
char * tesseract_lang;
|
||||||
} ScanCtx;
|
} ScanCtx;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@@ -35,7 +36,6 @@ struct {
|
|||||||
int no_color;
|
int no_color;
|
||||||
} LogCtx;
|
} LogCtx;
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
struct {
|
struct {
|
||||||
char *es_url;
|
char *es_url;
|
||||||
int batch_size;
|
int batch_size;
|
||||||
@@ -47,7 +47,6 @@ struct {
|
|||||||
char *b64credentials;
|
char *b64credentials;
|
||||||
struct index_t indices[16];
|
struct index_t indices[16];
|
||||||
} WebCtx;
|
} WebCtx;
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -27,13 +27,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]) {
|
||||||
@@ -68,7 +69,7 @@ void execute_update_script(const char *script, const char index_id[UUID_STR_LEN]
|
|||||||
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,7 +80,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,11 +133,10 @@ void elastic_flush() {
|
|||||||
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);
|
LOG_INFOF("elastic.c", "Indexed %d documents (%zukB) <%d>", count, buf_cur / 1024, r->status_code);
|
||||||
|
|
||||||
cJSON *ret_json = cJSON_Parse(r->body);
|
cJSON *ret_json = cJSON_Parse(r->body);
|
||||||
if (cJSON_GetObjectItem(ret_json, "errors")->valueint != 0) {
|
if (cJSON_GetObjectItem(ret_json, "errors")->valueint != 0) {
|
||||||
@@ -144,7 +144,7 @@ void elastic_flush() {
|
|||||||
cJSON_ArrayForEach(err, cJSON_GetObjectItem(ret_json, "items")) {
|
cJSON_ArrayForEach(err, cJSON_GetObjectItem(ret_json, "items")) {
|
||||||
if (cJSON_GetObjectItem(cJSON_GetObjectItem(err, "index"), "status")->valueint != 201) {
|
if (cJSON_GetObjectItem(cJSON_GetObjectItem(err, "index"), "status")->valueint != 201) {
|
||||||
char* str = cJSON_Print(err);
|
char* str = cJSON_Print(err);
|
||||||
fprintf(stderr, "%s\n", str);
|
LOG_ERRORF("elastic.c", "%s\n", str);
|
||||||
cJSON_free(str);
|
cJSON_free(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ 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);
|
||||||
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 +207,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 +232,32 @@ 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);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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);
|
||||||
@@ -172,8 +177,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();
|
||||||
|
|
||||||
@@ -229,7 +234,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:
|
||||||
@@ -275,6 +280,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) {
|
||||||
|
|||||||
36
src/main.c
36
src/main.c
@@ -1,16 +1,12 @@
|
|||||||
#include "sist.h"
|
#include "sist.h"
|
||||||
#include "ctx.h"
|
#include "ctx.h"
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
#define DESCRIPTION "Lightning-fast file system indexer and search tool."
|
#define DESCRIPTION "Lightning-fast file system indexer and search tool."
|
||||||
#else
|
|
||||||
#define DESCRIPTION "Lightning-fast file system indexer and search tool. (SCAN ONLY)"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#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.1.14";
|
static const char *const Version = "1.2.2";
|
||||||
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",
|
||||||
@@ -19,9 +15,7 @@ static const char *const usage[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void global_init() {
|
void global_init() {
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
curl_global_init(CURL_GLOBAL_NOTHING);
|
curl_global_init(CURL_GLOBAL_NOTHING);
|
||||||
#endif
|
|
||||||
av_log_set_level(AV_LOG_QUIET);
|
av_log_set_level(AV_LOG_QUIET);
|
||||||
opcInitLibrary();
|
opcInitLibrary();
|
||||||
}
|
}
|
||||||
@@ -35,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);
|
||||||
}
|
}
|
||||||
@@ -55,6 +50,7 @@ void sist2_scan(scan_args_t *args) {
|
|||||||
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));
|
||||||
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;
|
||||||
|
|
||||||
init_dir(ScanCtx.index.path);
|
init_dir(ScanCtx.index.path);
|
||||||
|
|
||||||
@@ -122,8 +118,6 @@ void sist2_scan(scan_args_t *args) {
|
|||||||
store_destroy(ScanCtx.index.store);
|
store_destroy(ScanCtx.index.store);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
|
|
||||||
void sist2_index(index_args_t *args) {
|
void sist2_index(index_args_t *args) {
|
||||||
|
|
||||||
IndexCtx.es_url = args->es_url;
|
IndexCtx.es_url = args->es_url;
|
||||||
@@ -137,8 +131,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +158,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);
|
||||||
@@ -198,18 +196,14 @@ void sist2_web(web_args_t *args) {
|
|||||||
serve(args->bind, args->port);
|
serve(args->bind, args->port);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char *argv[]) {
|
||||||
|
|
||||||
global_init();
|
global_init();
|
||||||
|
|
||||||
scan_args_t *scan_args = scan_args_create();
|
scan_args_t *scan_args = scan_args_create();
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
index_args_t *index_args = index_args_create();
|
index_args_t *index_args = index_args_create();
|
||||||
web_args_t *web_args = web_args_create();
|
web_args_t *web_args = web_args_create();
|
||||||
#endif
|
|
||||||
|
|
||||||
int arg_version = 0;
|
int arg_version = 0;
|
||||||
|
|
||||||
@@ -240,8 +234,9 @@ int main(int argc, const char *argv[]) {
|
|||||||
OPT_STRING(0, "archive", &scan_args->archive, "Archive file mode (skip|list|shallow|recurse). "
|
OPT_STRING(0, "archive", &scan_args->archive, "Archive file mode (skip|list|shallow|recurse). "
|
||||||
"skip: Don't parse, list: only get file names as text, "
|
"skip: Don't parse, list: only get file names as text, "
|
||||||
"shallow: Don't parse archives inside archives. DEFAULT: recurse"),
|
"shallow: Don't parse archives inside archives. DEFAULT: recurse"),
|
||||||
|
OPT_STRING(0, "ocr", &scan_args->tesseract_lang, "Tesseract language (use tesseract --list-langs to see "
|
||||||
|
"which are installed on your machine)"),
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
OPT_GROUP("Index options"),
|
OPT_GROUP("Index options"),
|
||||||
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url with port. DEFAULT=http://localhost:9200"),
|
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url with port. DEFAULT=http://localhost:9200"),
|
||||||
OPT_BOOLEAN('p', "print", &index_args->print, "Just print JSON documents to stdout."),
|
OPT_BOOLEAN('p', "print", &index_args->print, "Just print JSON documents to stdout."),
|
||||||
@@ -255,7 +250,6 @@ int main(int argc, const char *argv[]) {
|
|||||||
OPT_STRING(0, "bind", &web_args->bind, "Listen on this address. DEFAULT=localhost"),
|
OPT_STRING(0, "bind", &web_args->bind, "Listen on this address. DEFAULT=localhost"),
|
||||||
OPT_STRING(0, "port", &web_args->port, "Listen on this port. DEFAULT=4090"),
|
OPT_STRING(0, "port", &web_args->port, "Listen on this port. DEFAULT=4090"),
|
||||||
OPT_STRING(0, "auth", &web_args->credentials, "Basic auth in user:password format"),
|
OPT_STRING(0, "auth", &web_args->credentials, "Basic auth in user:password format"),
|
||||||
#endif
|
|
||||||
|
|
||||||
OPT_END(),
|
OPT_END(),
|
||||||
};
|
};
|
||||||
@@ -274,10 +268,8 @@ int main(int argc, const char *argv[]) {
|
|||||||
LogCtx.verbose = 1;
|
LogCtx.verbose = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
web_args->es_url = common_es_url;
|
web_args->es_url = common_es_url;
|
||||||
index_args->es_url = common_es_url;
|
index_args->es_url = common_es_url;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
argparse_usage(&argparse);
|
argparse_usage(&argparse);
|
||||||
@@ -292,7 +284,6 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
else if (strcmp(argv[0], "index") == 0) {
|
else if (strcmp(argv[0], "index") == 0) {
|
||||||
|
|
||||||
int err = index_args_validate(index_args, argc, argv);
|
int err = index_args_validate(index_args, argc, argv);
|
||||||
@@ -310,7 +301,6 @@ int main(int argc, const char *argv[]) {
|
|||||||
sist2_web(web_args);
|
sist2_web(web_args);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "Invalid command: '%s'\n", argv[0]);
|
fprintf(stderr, "Invalid command: '%s'\n", argv[0]);
|
||||||
argparse_usage(&argparse);
|
argparse_usage(&argparse);
|
||||||
@@ -320,10 +310,8 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
scan_args_destroy(scan_args);
|
scan_args_destroy(scan_args);
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
index_args_destroy(index_args);
|
index_args_destroy(index_args);
|
||||||
web_args_destroy(web_args);
|
web_args_destroy(web_args);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int st
|
|||||||
#define APPEND_TAG_META(doc, tag_, keyname) \
|
#define APPEND_TAG_META(doc, tag_, keyname) \
|
||||||
text_buffer_t tex = text_buffer_create(-1); \
|
text_buffer_t tex = text_buffer_create(-1); \
|
||||||
text_buffer_append_string0(&tex, tag_->value); \
|
text_buffer_append_string0(&tex, tag_->value); \
|
||||||
|
text_buffer_terminate_string(&tex); \
|
||||||
meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur); \
|
meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur); \
|
||||||
meta_tag->key = keyname; \
|
meta_tag->key = keyname; \
|
||||||
strcpy(meta_tag->strval, tex.dyn_buffer.buf); \
|
strcpy(meta_tag->strval, tex.dyn_buffer.buf); \
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#include "pdf.h"
|
#include "pdf.h"
|
||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
|
|
||||||
|
#define MIN_OCR_SIZE 128
|
||||||
|
__thread text_buffer_t thread_buffer;
|
||||||
|
|
||||||
|
|
||||||
fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
@@ -78,7 +82,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;
|
||||||
}
|
}
|
||||||
@@ -86,14 +91,13 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
|||||||
return cover;
|
return cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fz_err_callback(void *user, __attribute__((unused)) const char *message) {
|
void fz_err_callback(void *user, UNUSED(const char *message)) {
|
||||||
if (LogCtx.verbose) {
|
if (LogCtx.verbose) {
|
||||||
document_t *doc = (document_t *) user;
|
document_t *doc = (document_t *) user;
|
||||||
LOG_WARNINGF(doc->filepath, "FZ: %s", message)
|
LOG_WARNINGF(doc->filepath, "FZ: %s", message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
void init_ctx(fz_context *ctx, document_t *doc) {
|
void init_ctx(fz_context *ctx, document_t *doc) {
|
||||||
fz_disable_icc(ctx);
|
fz_disable_icc(ctx);
|
||||||
@@ -124,6 +128,40 @@ int read_stext_block(fz_stext_block *block, text_buffer_t *tex) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void fill_image(fz_context *ctx, UNUSED(fz_device *dev),
|
||||||
|
fz_image *img, UNUSED(fz_matrix ctm), UNUSED(float alpha),
|
||||||
|
UNUSED(fz_color_params color_params)) {
|
||||||
|
|
||||||
|
int l2factor = 0;
|
||||||
|
|
||||||
|
if (img->w > MIN_OCR_SIZE && img->h > MIN_OCR_SIZE) {
|
||||||
|
|
||||||
|
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) {
|
||||||
|
TessBaseAPI *api = TessBaseAPICreate();
|
||||||
|
TessBaseAPIInit3(api, TESS_DATAPATH, ScanCtx.tesseract_lang);
|
||||||
|
|
||||||
|
TessBaseAPISetImage(api, pix->samples, pix->w, pix->h, pix->n, pix->stride);
|
||||||
|
TessBaseAPISetSourceResolution(api, pix->xres);
|
||||||
|
|
||||||
|
char *text = TessBaseAPIGetUTF8Text(api);
|
||||||
|
size_t len = strlen(text);
|
||||||
|
text_buffer_append_string(&thread_buffer, text, len - 1);
|
||||||
|
LOG_DEBUGF(
|
||||||
|
"pdf.c",
|
||||||
|
"(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);
|
||||||
|
TessBaseAPIDelete(api);
|
||||||
|
fz_drop_pixmap(ctx, pix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
||||||
|
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
@@ -210,7 +248,7 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
|
|
||||||
if (ScanCtx.content_size > 0) {
|
if (ScanCtx.content_size > 0) {
|
||||||
fz_stext_options opts = {0};
|
fz_stext_options opts = {0};
|
||||||
text_buffer_t text_buf = text_buffer_create(ScanCtx.content_size);
|
thread_buffer = text_buffer_create(ScanCtx.content_size);
|
||||||
|
|
||||||
for (int current_page = 0; current_page < page_count; current_page++) {
|
for (int current_page = 0; current_page < page_count; current_page++) {
|
||||||
fz_page *page = NULL;
|
fz_page *page = NULL;
|
||||||
@@ -224,7 +262,7 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
err = ctx->error.errcode;
|
err = ctx->error.errcode;
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, ctx->error.message)
|
LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
text_buffer_destroy(&text_buf);
|
text_buffer_destroy(&thread_buffer);
|
||||||
fz_drop_page(ctx, page);
|
fz_drop_page(ctx, page);
|
||||||
fz_drop_stream(ctx, stream);
|
fz_drop_stream(ctx, stream);
|
||||||
fz_drop_document(ctx, fzdoc);
|
fz_drop_document(ctx, fzdoc);
|
||||||
@@ -235,6 +273,15 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
|
|
||||||
fz_stext_page *stext = fz_new_stext_page(ctx, fz_bound_page(ctx, page));
|
fz_stext_page *stext = fz_new_stext_page(ctx, fz_bound_page(ctx, page));
|
||||||
fz_device *dev = fz_new_stext_device(ctx, stext, &opts);
|
fz_device *dev = fz_new_stext_device(ctx, stext, &opts);
|
||||||
|
dev->stroke_path = NULL;
|
||||||
|
dev->stroke_text = NULL;
|
||||||
|
dev->clip_text = NULL;
|
||||||
|
dev->clip_stroke_path = NULL;
|
||||||
|
dev->clip_stroke_text = NULL;
|
||||||
|
|
||||||
|
if (ScanCtx.tesseract_lang != NULL) {
|
||||||
|
dev->fill_image = fill_image;
|
||||||
|
}
|
||||||
|
|
||||||
fz_var(err);
|
fz_var(err);
|
||||||
fz_try(ctx)
|
fz_try(ctx)
|
||||||
@@ -249,7 +296,7 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, ctx->error.message)
|
LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
text_buffer_destroy(&text_buf);
|
text_buffer_destroy(&thread_buffer);
|
||||||
fz_drop_page(ctx, page);
|
fz_drop_page(ctx, page);
|
||||||
fz_drop_stext_page(ctx, stext);
|
fz_drop_stext_page(ctx, stext);
|
||||||
fz_drop_stream(ctx, stream);
|
fz_drop_stream(ctx, stream);
|
||||||
@@ -260,7 +307,7 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
|
|
||||||
fz_stext_block *block = stext->first_block;
|
fz_stext_block *block = stext->first_block;
|
||||||
while (block != NULL) {
|
while (block != NULL) {
|
||||||
int ret = read_stext_block(block, &text_buf);
|
int ret = read_stext_block(block, &thread_buffer);
|
||||||
if (ret == TEXT_BUF_FULL) {
|
if (ret == TEXT_BUF_FULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -269,18 +316,18 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
fz_drop_stext_page(ctx, stext);
|
fz_drop_stext_page(ctx, stext);
|
||||||
fz_drop_page(ctx, page);
|
fz_drop_page(ctx, page);
|
||||||
|
|
||||||
if (text_buf.dyn_buffer.cur >= text_buf.dyn_buffer.size) {
|
if (thread_buffer.dyn_buffer.cur >= thread_buffer.dyn_buffer.size) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text_buffer_terminate_string(&text_buf);
|
text_buffer_terminate_string(&thread_buffer);
|
||||||
|
|
||||||
meta_line_t *meta_content = malloc(sizeof(meta_line_t) + text_buf.dyn_buffer.cur);
|
meta_line_t *meta_content = malloc(sizeof(meta_line_t) + thread_buffer.dyn_buffer.cur);
|
||||||
meta_content->key = MetaContent;
|
meta_content->key = MetaContent;
|
||||||
memcpy(meta_content->strval, text_buf.dyn_buffer.buf, text_buf.dyn_buffer.cur);
|
memcpy(meta_content->strval, thread_buffer.dyn_buffer.buf, thread_buffer.dyn_buffer.cur);
|
||||||
APPEND_META(doc, meta_content)
|
APPEND_META(doc, meta_content)
|
||||||
|
|
||||||
text_buffer_destroy(&text_buf);
|
text_buffer_destroy(&thread_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fz_drop_stream(ctx, stream);
|
fz_drop_stream(ctx, stream);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ void parse_text(int bytes_read, struct vfile *f, char *buf, document_t *doc) {
|
|||||||
}
|
}
|
||||||
text_buffer_t tex = text_buffer_create(ScanCtx.content_size);
|
text_buffer_t tex = text_buffer_create(ScanCtx.content_size);
|
||||||
text_buffer_append_string(&tex, intermediate_buf, intermediate_buf_len);
|
text_buffer_append_string(&tex, intermediate_buf, intermediate_buf_len);
|
||||||
|
text_buffer_terminate_string(&tex);
|
||||||
|
|
||||||
meta_line_t *meta = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur);
|
meta_line_t *meta = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur);
|
||||||
meta->key = MetaContent;
|
meta->key = MetaContent;
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#define SIST_H
|
#define SIST_H
|
||||||
|
|
||||||
#define UUID_STR_LEN 37
|
#define UUID_STR_LEN 37
|
||||||
|
#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>
|
||||||
@@ -32,15 +34,15 @@
|
|||||||
#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>
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
#include <onion/onion.h>
|
#include <onion/onion.h>
|
||||||
#include <onion/handler.h>
|
#include <onion/handler.h>
|
||||||
#include <onion/block.h>
|
#include <onion/block.h>
|
||||||
#include <onion/shortcuts.h>
|
#include <onion/shortcuts.h>
|
||||||
#include <onion/codecs.h>
|
#include <onion/codecs.h>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "cJSON/cJSON.h"
|
#include "cJSON/cJSON.h"
|
||||||
|
|
||||||
@@ -62,12 +64,10 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "utf8.h/utf8.h"
|
#include "utf8.h/utf8.h"
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
#include "src/index/elastic.h"
|
#include "src/index/elastic.h"
|
||||||
#include "index/web.h"
|
#include "index/web.h"
|
||||||
#include "web/serve.h"
|
#include "web/serve.h"
|
||||||
#include "web/auth_basic.h"
|
#include "web/auth_basic.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ enum metakey {
|
|||||||
MetaParent = 14 | META_STR_MASK,
|
MetaParent = 14 | META_STR_MASK,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#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[6];
|
||||||
@@ -41,6 +45,7 @@ typedef struct index_descriptor {
|
|||||||
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 {
|
||||||
@@ -70,8 +75,6 @@ typedef struct document {
|
|||||||
short ext;
|
short ext;
|
||||||
meta_line_t *meta_head;
|
meta_line_t *meta_head;
|
||||||
meta_line_t *meta_tail;
|
meta_line_t *meta_tail;
|
||||||
struct document *child_head;
|
|
||||||
struct document *child_tail;
|
|
||||||
char *filepath;
|
char *filepath;
|
||||||
} document_t;
|
} document_t;
|
||||||
|
|
||||||
@@ -79,8 +82,6 @@ typedef struct vfile vfile_t;
|
|||||||
|
|
||||||
typedef int (*read_func_t)(struct vfile *, void *buf, size_t size);
|
typedef int (*read_func_t)(struct vfile *, void *buf, size_t size);
|
||||||
|
|
||||||
typedef int (*seek_func_t)(struct vfile *, size_t size, int whence);
|
|
||||||
|
|
||||||
typedef void (*close_func_t)(struct vfile *);
|
typedef void (*close_func_t)(struct vfile *);
|
||||||
|
|
||||||
typedef struct vfile {
|
typedef struct vfile {
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ int text_buffer_append_string(text_buffer_t *buf, char *str, size_t len) {
|
|||||||
(0xe0 == (0xf0 & str[0]) && len < 3) ||
|
(0xe0 == (0xf0 & str[0]) && len < 3) ||
|
||||||
(0xc0 == (0xe0 & str[0]) && len == 1) ||
|
(0xc0 == (0xe0 & str[0]) && len == 1) ||
|
||||||
*(str) == 0) {
|
*(str) == 0) {
|
||||||
text_buffer_terminate_string(buf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +157,6 @@ int text_buffer_append_string(text_buffer_t *buf, char *str, size_t len) {
|
|||||||
text_buffer_append_char(buf, c);
|
text_buffer_append_char(buf, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text_buffer_terminate_string(buf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +167,6 @@ int text_buffer_append_string0(text_buffer_t *buf, char *str) {
|
|||||||
text_buffer_append_char(buf, c);
|
text_buffer_append_char(buf, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text_buffer_terminate_string(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int text_buffer_append_char(text_buffer_t *buf, int c) {
|
int text_buffer_append_char(text_buffer_t *buf, int c) {
|
||||||
|
|||||||
@@ -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 >= (int)'!')
|
#define SHOULD_KEEP_CHAR(c) ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'z') || (c > 127))
|
||||||
|
|
||||||
|
|
||||||
typedef struct dyn_buffer {
|
typedef struct dyn_buffer {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ 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) {
|
||||||
@@ -254,7 +254,7 @@ 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 scroll(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_GET) {
|
if ((flags & OR_METHODS) != OR_GET) {
|
||||||
@@ -327,7 +327,7 @@ int serve_file_from_disk(cJSON *json, index_t *idx, onion_request *req, onion_re
|
|||||||
return chunked_response_file(full_path, mime, 1, req, res);
|
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 +353,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;
|
||||||
@@ -424,6 +457,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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -153,11 +153,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"] + (doc["extension"] ? "." + doc["extension"] : ""));
|
||||||
*/
|
|
||||||
|
const tbody = $("<tbody>");
|
||||||
|
$("#modal-body").empty()
|
||||||
|
.append($("<table class='table table-sm'>")
|
||||||
|
.append($("<thead>")
|
||||||
|
.append($("<tr>")
|
||||||
|
.append($("<th>").text("Field"))
|
||||||
|
.append($("<th>").text("Value"))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.append(tbody)
|
||||||
|
);
|
||||||
|
|
||||||
|
const displayFields = new Set([
|
||||||
|
"mime", "size", "mtime", "path", "title", "width", "height", "duration", "audioc", "videoc",
|
||||||
|
"bitrate", "artist", "album", "album_artist", "genre", "title", "font_name", "tag"
|
||||||
|
]);
|
||||||
|
Object.keys(doc)
|
||||||
|
.filter(key => key.startsWith("_keyword.") || key.startsWith("_text.") || displayFields.has(key))
|
||||||
|
.forEach(key => {
|
||||||
|
tbody.append($("<tr>")
|
||||||
|
.append($("<td>").text(key))
|
||||||
|
.append($("<td>").text(doc[key]))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
if (doc.hasOwnProperty("content") && doc["content"]) {
|
||||||
|
$("#modal-body").append($("<div class='content-div'>").text(doc["content"]))
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#modal").modal();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createDocCard(hit) {
|
function createDocCard(hit) {
|
||||||
let docCard = document.createElement("div");
|
let docCard = document.createElement("div");
|
||||||
docCard.setAttribute("class", "card");
|
docCard.setAttribute("class", "card");
|
||||||
@@ -172,6 +205,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 +305,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);
|
||||||
@@ -352,6 +394,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 +422,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 +432,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);
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ $.jsonPost("i").then(resp => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getDocumentInfo(id) {
|
||||||
|
return $.getJSON("d/" + id)
|
||||||
|
}
|
||||||
|
|
||||||
function handleTreeClick(tree) {
|
function handleTreeClick(tree) {
|
||||||
return (event, node, handler) => {
|
return (event, node, handler) => {
|
||||||
event.preventTreeDefault();
|
event.preventTreeDefault();
|
||||||
|
|||||||
@@ -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.1.14</span>
|
<span class="badge badge-pill version">v1.2.2</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>
|
||||||
@@ -65,6 +65,20 @@
|
|||||||
</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 id="searchResults"></div>
|
<div id="searchResults"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user