mirror of
https://github.com/simon987/sist2.git
synced 2025-12-13 15:29:04 +00:00
Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 9a56b959d3 | |||
| 5e3a2dbcc2 | |||
| 573f94f24e | |||
| f5db78a69f | |||
| 5a2820d339 | |||
| b7f13f425c | |||
| d1a2f9b1d5 | |||
| 71f17986db | |||
| acdd2fb3c1 | |||
| 0cda6c00e1 | |||
| 14d0e5a1e1 | |||
| 0d06d39281 | |||
| 80708ca636 | |||
|
|
43b7b40dc4 | ||
| d051f541e2 | |||
| 0eefbac7b4 | |||
| 663f8e21c1 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,3 +15,4 @@ bundle*.css
|
|||||||
bundle.js
|
bundle.js
|
||||||
*.a
|
*.a
|
||||||
vgcore.*
|
vgcore.*
|
||||||
|
build/
|
||||||
|
|||||||
24
.gitmodules
vendored
24
.gitmodules
vendored
@@ -31,15 +31,15 @@
|
|||||||
[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"]
|
[submodule "lib/libpng"]
|
||||||
path = lib/libxml2
|
path = lib/libpng
|
||||||
url = https://github.com/GNOME/libxml2
|
url = https://github.com/glennrp/libpng
|
||||||
|
|||||||
69
.teamcity/settings.kts
vendored
Normal file
69
.teamcity/settings.kts
vendored
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import jetbrains.buildServer.configs.kotlin.v2019_2.*
|
||||||
|
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.ExecBuildStep
|
||||||
|
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.exec
|
||||||
|
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.vcs
|
||||||
|
import jetbrains.buildServer.configs.kotlin.v2019_2.vcs.GitVcsRoot
|
||||||
|
|
||||||
|
/*
|
||||||
|
The settings script is an entry point for defining a TeamCity
|
||||||
|
project hierarchy. The script should contain a single call to the
|
||||||
|
project() function with a Project instance or an init function as
|
||||||
|
an argument.
|
||||||
|
|
||||||
|
VcsRoots, BuildTypes, Templates, and subprojects can be
|
||||||
|
registered inside the project using the vcsRoot(), buildType(),
|
||||||
|
template(), and subProject() methods respectively.
|
||||||
|
|
||||||
|
To debug settings scripts in command-line, run the
|
||||||
|
|
||||||
|
mvnDebug org.jetbrains.teamcity:teamcity-configs-maven-plugin:generate
|
||||||
|
|
||||||
|
command and attach your debugger to the port 8000.
|
||||||
|
|
||||||
|
To debug in IntelliJ Idea, open the 'Maven Projects' tool window (View
|
||||||
|
-> Tool Windows -> Maven Projects), find the generate task node
|
||||||
|
(Plugins -> teamcity-configs -> teamcity-configs:generate), the
|
||||||
|
'Debug' option is available in the context menu for the task.
|
||||||
|
*/
|
||||||
|
|
||||||
|
version = "2019.2"
|
||||||
|
|
||||||
|
project {
|
||||||
|
|
||||||
|
vcsRoot(HttpsGithubComSimon987sist2refsHeadsMaster)
|
||||||
|
|
||||||
|
buildType(Build)
|
||||||
|
}
|
||||||
|
|
||||||
|
object Build : BuildType({
|
||||||
|
name = "Build"
|
||||||
|
|
||||||
|
artifactRules = """
|
||||||
|
sist2
|
||||||
|
sist2_scan
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
vcs {
|
||||||
|
root(HttpsGithubComSimon987sist2refsHeadsMaster)
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
exec {
|
||||||
|
name = "Build"
|
||||||
|
path = "./ci/build.sh"
|
||||||
|
dockerImage = "simon987/general_ci"
|
||||||
|
dockerImagePlatform = ExecBuildStep.ImagePlatform.Linux
|
||||||
|
dockerPull = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
triggers {
|
||||||
|
vcs {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
object HttpsGithubComSimon987sist2refsHeadsMaster : GitVcsRoot({
|
||||||
|
name = "https://github.com/simon987/sist2#refs/heads/master"
|
||||||
|
url = "https://github.com/simon987/sist2"
|
||||||
|
})
|
||||||
318
CMakeLists.txt
318
CMakeLists.txt
@@ -1,95 +1,56 @@
|
|||||||
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
|
src/sist.h
|
||||||
src/sist.h
|
src/io/walk.h src/io/walk.c
|
||||||
src/io/walk.h src/io/walk.c
|
src/parsing/media.h src/parsing/media.c
|
||||||
src/parsing/media.h src/parsing/media.c
|
src/parsing/pdf.h src/parsing/pdf.c
|
||||||
src/parsing/pdf.h src/parsing/pdf.c
|
src/io/store.h src/io/store.c
|
||||||
src/io/store.h src/io/store.c
|
src/tpool.h src/tpool.c
|
||||||
src/tpool.h src/tpool.c
|
src/parsing/parse.h src/parsing/parse.c
|
||||||
src/parsing/parse.h src/parsing/parse.c
|
src/io/serialize.h src/io/serialize.c
|
||||||
src/io/serialize.h src/io/serialize.c
|
src/parsing/mime.h src/parsing/mime.c src/parsing/mime_generated.c
|
||||||
src/parsing/mime.h src/parsing/mime.c src/parsing/mime_generated.c
|
src/parsing/text.h src/parsing/text.c
|
||||||
src/parsing/text.h src/parsing/text.c
|
src/index/web.c src/index/web.h
|
||||||
src/index/web.c src/index/web.h
|
src/web/serve.c src/web/serve.h
|
||||||
src/web/serve.c src/web/serve.h
|
src/web/auth_basic.h src/web/auth_basic.c
|
||||||
src/web/auth_basic.h src/web/auth_basic.c
|
src/index/elastic.c src/index/elastic.h
|
||||||
src/index/elastic.c src/index/elastic.h
|
src/util.c src/util.h
|
||||||
src/util.c src/util.h
|
src/ctx.h src/types.h src/parsing/font.c src/parsing/font.h
|
||||||
src/ctx.h src/types.h src/parsing/font.c src/parsing/font.h
|
src/parsing/arc.c src/parsing/arc.h
|
||||||
|
src/parsing/doc.c src/parsing/doc.h
|
||||||
|
src/log.c src/log.h
|
||||||
|
|
||||||
# argparse
|
# argparse
|
||||||
argparse/argparse.h argparse/argparse.c
|
argparse/argparse.h argparse/argparse.c
|
||||||
|
|
||||||
# cJSON
|
# cJSON
|
||||||
cJSON/cJSON.h cJSON/cJSON.c
|
cJSON/cJSON.h cJSON/cJSON.c
|
||||||
|
|
||||||
# LMDB
|
# LMDB
|
||||||
lmdb/libraries/liblmdb/lmdb.h lmdb/libraries/liblmdb/mdb.c
|
lmdb/libraries/liblmdb/lmdb.h lmdb/libraries/liblmdb/mdb.c
|
||||||
lmdb/libraries/liblmdb/midl.h lmdb/libraries/liblmdb/midl.c
|
lmdb/libraries/liblmdb/midl.h lmdb/libraries/liblmdb/midl.c
|
||||||
src/cli.c src/cli.h
|
src/cli.c src/cli.h
|
||||||
|
|
||||||
# utf8.h
|
# utf8.h
|
||||||
utf8.h/utf8.h
|
utf8.h/utf8.h
|
||||||
src/parsing/arc.c src/parsing/arc.h src/parsing/doc.c src/parsing/doc.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
|
|
||||||
|
|
||||||
# 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
|
|
||||||
src/parsing/arc.c src/parsing/arc.h src/parsing/doc.c src/parsing/doc.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/")
|
||||||
|
|
||||||
find_package(LibMagic REQUIRED)
|
|
||||||
find_package(FFmpeg REQUIRED)
|
|
||||||
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)
|
||||||
pkg_check_modules(GOBJECT REQUIRED gobject-2.0)
|
pkg_check_modules(GOBJECT REQUIRED gobject-2.0)
|
||||||
pkg_check_modules(UUID REQUIRED uuid)
|
pkg_check_modules(UUID REQUIRED uuid)
|
||||||
|
|
||||||
add_definitions(${LIBMAGIC_CFLAGS_OTHER})
|
|
||||||
add_definitions(${UUID_CFLAGS_OTHER})
|
add_definitions(${UUID_CFLAGS_OTHER})
|
||||||
add_definitions(${GLIB_CFLAGS_OTHER})
|
add_definitions(${GLIB_CFLAGS_OTHER})
|
||||||
add_definitions(${GOBJECT_CFLAGS_OTHER})
|
add_definitions(${GOBJECT_CFLAGS_OTHER})
|
||||||
@@ -99,166 +60,87 @@ 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}
|
||||||
${LIBMAGIC_INCLUDE_DIRS}
|
${GLIB_INCLUDE_DIRS}
|
||||||
${GOBJECT_INCLUDE_DIRS}
|
${PROJECT_SOURCE_DIR}/lib/ffmpeg/
|
||||||
${OPENSSL_INCLUDE_DIR}
|
${FREETYPE_INCLUDE_DIRS}
|
||||||
${FFMPEG_INCLUDE_DIRS}
|
${UUID_INCLUDE_DIRS}
|
||||||
${GLIB_INCLUDE_DIRS}
|
${PROJECT_SOURCE_DIR}/
|
||||||
${FREETYPE_INCLUDE_DIRS}
|
${PROJECT_SOURCE_DIR}/lmdb/libraries/liblmdb/
|
||||||
${UUID_INCLUDE_DIRS}
|
${PROJECT_SOURCE_DIR}/lib/onion/src/
|
||||||
${PROJECT_SOURCE_DIR}/
|
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
||||||
${PROJECT_SOURCE_DIR}/lmdb/libraries/liblmdb/
|
${PROJECT_SOURCE_DIR}/include/
|
||||||
${PROJECT_SOURCE_DIR}/lib/onion/src/
|
/usr/include/libxml2/
|
||||||
${PROJECT_SOURCE_DIR}/lib/mupdf/include/
|
${PROJECT_SOURCE_DIR}/lib/tesseract/include/
|
||||||
${PROJECT_SOURCE_DIR}/include/
|
)
|
||||||
/usr/include/libxml2/
|
target_link_directories(
|
||||||
)
|
sist2 PUBLIC
|
||||||
target_link_directories(
|
${UUID_LIBRARY_DIRS}
|
||||||
sist2 PUBLIC
|
)
|
||||||
${UUID_LIBRARY_DIRS}
|
|
||||||
${FFMPEG_LIBRARY_DIRS}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
target_compile_options(sist2
|
||||||
|
PRIVATE
|
||||||
|
-Ofast
|
||||||
|
# -march=native
|
||||||
|
-fPIC
|
||||||
|
-fno-stack-protector
|
||||||
|
-fomit-frame-pointer
|
||||||
|
)
|
||||||
|
|
||||||
target_compile_options(sist2
|
TARGET_LINK_LIBRARIES(
|
||||||
PRIVATE
|
sist2
|
||||||
-Ofast
|
|
||||||
# -march=native
|
|
||||||
-fno-stack-protector
|
|
||||||
-fomit-frame-pointer
|
|
||||||
)
|
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(
|
${GLIB_LIBRARIES}
|
||||||
sist2
|
${GOBJECT_LIBRARIES}
|
||||||
|
${UUID_LIBRARIES}
|
||||||
|
|
||||||
${GLIB_LIBRARIES}
|
# ffmpeg
|
||||||
${GOBJECT_LIBRARIES}
|
${PROJECT_SOURCE_DIR}/lib/libavcodec.a
|
||||||
${UUID_LIBRARIES}
|
${PROJECT_SOURCE_DIR}/lib/libavformat.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libavutil.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libswscale.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libswresample.a
|
||||||
|
|
||||||
# ffmpeg
|
# mupdf
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavcodec.a
|
${PROJECT_SOURCE_DIR}/lib/libmupdf.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavformat.a
|
${PROJECT_SOURCE_DIR}/lib/libmupdf-third.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libavutil.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libswscale.a
|
|
||||||
${PROJECT_SOURCE_DIR}/lib/libswresample.a
|
|
||||||
# ${FFMPEG_LIBRARIES}
|
|
||||||
# swscale
|
|
||||||
|
|
||||||
# mupdf
|
# onion
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmupdf.a
|
${PROJECT_SOURCE_DIR}/lib/libonion_static.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libmupdf-third.a
|
|
||||||
|
|
||||||
# onion
|
pthread
|
||||||
${PROJECT_SOURCE_DIR}/lib/libonion_static.a
|
|
||||||
|
|
||||||
pthread
|
m
|
||||||
curl
|
bz2
|
||||||
m
|
${PROJECT_SOURCE_DIR}/lib/libmagic.a
|
||||||
bz2
|
${PROJECT_SOURCE_DIR}/lib/libharfbuzz.a
|
||||||
magic
|
${PROJECT_SOURCE_DIR}/lib/libopenjp2.a
|
||||||
${PROJECT_SOURCE_DIR}/lib/libharfbuzz.a
|
freetype
|
||||||
${PROJECT_SOURCE_DIR}/lib/libopenjp2.a
|
archive
|
||||||
freetype
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
endif ()
|
${PROJECT_SOURCE_DIR}/lib/libtesseract.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/liblept.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libtiff.a
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libpng16.a
|
||||||
|
stdc++
|
||||||
|
|
||||||
if (WITH_SIST2_SCAN)
|
# curl
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/libcurl.a
|
||||||
set_target_properties(
|
${PROJECT_SOURCE_DIR}/lib/libcrypto.a
|
||||||
sist2_scan
|
${PROJECT_SOURCE_DIR}/lib/libssl.a
|
||||||
PROPERTIES COMPILE_DEFINITIONS SIST_SCAN_ONLY
|
dl
|
||||||
)
|
)
|
||||||
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}
|
|
||||||
${FFMPEG_INCLUDE_DIRS}
|
|
||||||
${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}
|
|
||||||
${FFMPEG_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,8 +2,21 @@ 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
|
||||||
|
|
||||||
|
ENV LANG C.UTF-8
|
||||||
|
ENV LC_ALL C.UTF-8
|
||||||
|
|
||||||
ENTRYPOINT ["/root/sist2"]
|
ENTRYPOINT ["/root/sist2"]
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
rm ./sist2
|
rm ./sist2
|
||||||
cp ../sist2 .
|
cp ../sist2 .
|
||||||
|
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
|
||||||
45
README.md
45
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
|
||||||
|
|
||||||
@@ -11,21 +12,24 @@ sist2 (Simple incremental search tool)
|
|||||||
|
|
||||||
* Fast, low memory usage, multi-threaded
|
* Fast, low memory usage, multi-threaded
|
||||||
* Portable (all its features are packaged in a single executable)
|
* Portable (all its features are packaged in a single executable)
|
||||||
* Extracts text from common file types\*
|
* Extracts text from common file types \*
|
||||||
* Generates thumbnails\*
|
* Generates thumbnails \*
|
||||||
* 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 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`
|
||||||
|
|
||||||
|
|
||||||
@@ -35,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**
|
||||||
@@ -85,10 +92,10 @@ 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` | [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 |
|
||||||
@@ -111,6 +118,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
|
||||||
|
|
||||||
@@ -121,15 +143,10 @@ binaries.
|
|||||||
|
|
||||||
*(Debian)*
|
*(Debian)*
|
||||||
```bash
|
```bash
|
||||||
apt install git cmake pkg-config libglib2.0-dev\
|
apt install git cmake pkg-config libglib2.0-dev \
|
||||||
libssl-dev uuid-dev libavformat-dev libswscale-dev \
|
libssl-dev uuid-dev python3 libmagic-dev libfreetype6-dev \
|
||||||
python3 libmagic-dev libfreetype6-dev libcurl-dev \
|
libcurl-dev libbz2-dev yasm libharfbuzz-dev ragel \
|
||||||
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
|
||||||
|
|||||||
7
ci/build.sh
Normal file
7
ci/build.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
./scripts/get_static_libs.sh
|
||||||
|
|
||||||
|
cmake .
|
||||||
|
make
|
||||||
|
strip sist2
|
||||||
1
lib/leptonica
Submodule
1
lib/leptonica
Submodule
Submodule lib/leptonica added at cc03be70fd
Submodule lib/libarchive deleted from 6f4fceb714
Binary file not shown.
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
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
2
mime.csv
2
mime.csv
@@ -252,7 +252,7 @@ text/html, acgi|htm|html|htmls|htx|shtml
|
|||||||
text/javascript, js
|
text/javascript, js
|
||||||
text/mcf, mcf
|
text/mcf, mcf
|
||||||
text/pascal, pas
|
text/pascal, pas
|
||||||
text/plain, com|cmd|conf|def|g|idc|list|lst|mar|sdml|text|txt|md|groovy|license|properties|desktop|ini|rst|cmake|ipynb|readme|less|lo|go|yml|d|cs|hpp|srt|nfo|sfv|m3u
|
text/plain, com|cmd|conf|def|g|idc|list|lst|mar|sdml|text|txt|md|groovy|license|properties|desktop|ini|rst|cmake|ipynb|readme|less|lo|go|yml|d|cs|hpp|srt|nfo|sfv|m3u|csv|eml
|
||||||
text/richtext, rt|rtf|rtx
|
text/richtext, rt|rtf|rtx
|
||||||
text/rtf,
|
text/rtf,
|
||||||
text/scriplet, wsc
|
text/scriplet, wsc
|
||||||
|
|||||||
|
@@ -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": [
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
THREADS=$(nproc)
|
||||||
|
|
||||||
cd lib
|
cd lib
|
||||||
|
|
||||||
cd mupdf
|
cd mupdf
|
||||||
USE_SYSTEM_HARFBUZZ=yes USE_SYSTEM_OPENJPEG=yes HAVE_X11=no HAVE_GLUT=no make -j 4
|
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 .
|
||||||
@@ -10,17 +13,16 @@ 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 -march=native -DNDEBUG -fPIC"
|
||||||
cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-O3"
|
make -j $THREADS
|
||||||
make -j 4
|
|
||||||
cd ..
|
cd ..
|
||||||
mv openjpeg/bin/libopenjp2.a .
|
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 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv harfbuzz/src/.libs/libharfbuzz.a .
|
mv harfbuzz/src/.libs/libharfbuzz.a .
|
||||||
|
|
||||||
@@ -30,8 +32,9 @@ 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\
|
||||||
make -j 4
|
--extra-cflags=-fPIC
|
||||||
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
mv ffmpeg/libavcodec/libavcodec.a .
|
mv ffmpeg/libavcodec/libavcodec.a .
|
||||||
@@ -48,14 +51,14 @@ cmake -DONION_USE_SSL=false -DONION_USE_PAM=false -DONION_USE_PNG=false -DONION_
|
|||||||
-DONION_USE_JPEG=false -DONION_USE_XML2=false -DONION_USE_SYSTEMD=false -DONION_USE_SQLITE3=false \
|
-DONION_USE_JPEG=false -DONION_USE_XML2=false -DONION_USE_SYSTEMD=false -DONION_USE_SQLITE3=false \
|
||||||
-DONION_USE_REDIS=false -DONION_USE_GC=false -DONION_USE_TESTS=false -DONION_EXAMPLES=false \
|
-DONION_USE_REDIS=false -DONION_USE_GC=false -DONION_USE_TESTS=false -DONION_EXAMPLES=false \
|
||||||
-DONION_USE_BINDINGS_CPP=false ..
|
-DONION_USE_BINDINGS_CPP=false ..
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ../..
|
cd ../..
|
||||||
|
|
||||||
mv onion/build/src/onion/libonion_static.a .
|
mv onion/build/src/onion/libonion_static.a .
|
||||||
|
|
||||||
#bzip2
|
#bzip2
|
||||||
cd bzip2-1.0.6
|
cd bzip2-1.0.6
|
||||||
make -j 4
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv bzip2-1.0.6/libbz2.a .
|
mv bzip2-1.0.6/libbz2.a .
|
||||||
|
|
||||||
@@ -63,47 +66,63 @@ mv bzip2-1.0.6/libbz2.a .
|
|||||||
cd libmagic
|
cd libmagic
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure --enable-static --disable-shared
|
./configure --enable-static --disable-shared
|
||||||
make -j 4
|
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 -DBUILD_TESTS=off -DCMAKE_BUILD_TYPE=Release \
|
||||||
|
-DCMAKE_CXX_FLAGS="-fPIC" -DAUTO_OPTIMIZE=off ..
|
||||||
|
make -j $THREADS
|
||||||
|
cd ../..
|
||||||
|
mv tesseract/build/libtesseract.a .
|
||||||
|
|
||||||
|
# leptonica
|
||||||
|
cd leptonica
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
|
CFLAGS="-fPIC" ./configure --without-zlib --without-jpeg --without-giflib \
|
||||||
|
--without-giflib --without-libwebp --without-libwebpmux --without-libopenjpeg \
|
||||||
|
--enable-static --disable-shared
|
||||||
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
./configure --without-nettle --without-expat --without-xml2 --without-openssl
|
mv leptonica/src/.libs/liblept.a .
|
||||||
make -j 4
|
|
||||||
cd ..
|
|
||||||
mv libarchive/.libs/libarchive.a .
|
|
||||||
|
|
||||||
# lz4
|
# tiff
|
||||||
cd lz4
|
cd libtiff
|
||||||
make -j 4
|
|
||||||
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
|
CFLAGS="-fPIC" CXXFLAGS="-fPIC" CXX_FLAGS="-fPIC" ./configure --enable-static --disable-shared --disable-lzw --disable-jpeg --disable-webp \
|
||||||
make -j 4
|
--disable-lzma --disable-zstd --disable-jbig
|
||||||
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv xz-5.2.3/src/liblzma/.libs/liblzma.a .
|
mv libtiff/libtiff/.libs/libtiff.a .
|
||||||
|
|
||||||
# zstd
|
# png
|
||||||
cd zstd
|
cd libpng
|
||||||
make -j 4
|
CFLAGS="-fPIC" ./configure --enable-static --disable-shared
|
||||||
|
make -j $THREADS
|
||||||
cd ..
|
cd ..
|
||||||
mv zstd/lib/libzstd.a .
|
mv libpng/.libs/libpng16.a .
|
||||||
|
|
||||||
# xml2
|
# openssl...
|
||||||
cd libxml2
|
git clone --depth 1 -b OpenSSL_1_1_0-stable https://github.com/openssl/openssl
|
||||||
./autogen.sh --without-zlib --without-lzma
|
cd openssl
|
||||||
make
|
./config --prefix=$(pwd)/../ssl
|
||||||
|
make depend
|
||||||
|
make -j $THREADS
|
||||||
|
make install
|
||||||
cd ..
|
cd ..
|
||||||
mv libxml2/.libs/libxml2.a .
|
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 ..
|
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)))
|
||||||
|
|||||||
79
src/cli.c
79
src/cli.c
@@ -1,4 +1,7 @@
|
|||||||
#include "cli.h"
|
#include "cli.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
|
||||||
@@ -12,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);
|
||||||
@@ -34,8 +44,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);
|
||||||
@@ -46,8 +54,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");
|
||||||
@@ -134,13 +140,49 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
fprintf(stderr, "Archive mode must be one of (skip, list, shallow, recurse), got '%s'", args->archive);
|
fprintf(stderr, "Archive mode must be one of (skip, list, shallow, recurse), got '%s'", args->archive);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->tesseract_lang != NULL) {
|
||||||
|
TessBaseAPI *api = TessBaseAPICreate();
|
||||||
|
|
||||||
|
char filename[128];
|
||||||
|
sprintf(filename, "%s.traineddata", args->tesseract_lang);
|
||||||
|
const char * path = find_file_in_paths(TESS_DATAPATHS, filename);
|
||||||
|
if (path == NULL) {
|
||||||
|
LOG_FATAL("cli.c", "Could not find tesseract language file!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TessBaseAPIInit3(api, path, args->tesseract_lang);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "Could not initialize tesseract with lang '%s'\n", args->tesseract_lang);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
TessBaseAPIEnd(api);
|
||||||
|
TessBaseAPIDelete(api);
|
||||||
|
|
||||||
|
args->tesseract_path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DEBUGF("cli.c", "arg quality=%f", args->quality)
|
||||||
|
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 threads=%d", args->threads)
|
||||||
|
LOG_DEBUGF("cli.c", "arg incremental=%s", args->incremental)
|
||||||
|
LOG_DEBUGF("cli.c", "arg output=%s", args->output)
|
||||||
|
LOG_DEBUGF("cli.c", "arg rewrite_url=%s", args->rewrite_url)
|
||||||
|
LOG_DEBUGF("cli.c", "arg name=%s", args->name)
|
||||||
|
LOG_DEBUGF("cli.c", "arg depth=%d", args->depth)
|
||||||
|
LOG_DEBUGF("cli.c", "arg path=%s", args->path)
|
||||||
|
LOG_DEBUGF("cli.c", "arg archive=%s", args->archive)
|
||||||
|
LOG_DEBUGF("cli.c", "arg tesseract_lang=%s", args->tesseract_lang)
|
||||||
|
LOG_DEBUGF("cli.c", "arg tesseract_path=%s", args->tesseract_path)
|
||||||
|
|
||||||
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;
|
||||||
@@ -189,11 +231,21 @@ int index_args_validate(index_args_t *args, int argc, const char **argv) {
|
|||||||
args->batch_size = DEFAULT_BATCH_SIZE;
|
args->batch_size = DEFAULT_BATCH_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_DEBUGF("cli.c", "arg es_url=%s", args->es_url)
|
||||||
|
LOG_DEBUGF("cli.c", "arg index_path=%s", args->index_path)
|
||||||
|
LOG_DEBUGF("cli.c", "arg script_path=%s", args->script_path)
|
||||||
|
LOG_DEBUGF("cli.c", "arg script=%s", args->script)
|
||||||
|
LOG_DEBUGF("cli.c", "arg print=%d", args->print)
|
||||||
|
LOG_DEBUGF("cli.c", "arg batch_size=%d", args->batch_size)
|
||||||
|
LOG_DEBUGF("cli.c", "arg force_reset=%d", args->force_reset)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -223,10 +275,21 @@ int web_args_validate(web_args_t *args, int argc, const char **argv) {
|
|||||||
for (int i = 0; i < args->index_count; i++) {
|
for (int i = 0; i < args->index_count; i++) {
|
||||||
char *abs_path = abspath(args->indices[i]);
|
char *abs_path = abspath(args->indices[i]);
|
||||||
if (abs_path == NULL) {
|
if (abs_path == NULL) {
|
||||||
fprintf(stderr, "File not found: %s\n", abs_path);
|
fprintf(stderr, "File not found: %s\n", args->indices[i]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_DEBUGF("cli.c", "arg es_url=%s", args->es_url)
|
||||||
|
LOG_DEBUGF("cli.c", "arg bind=%s", args->bind)
|
||||||
|
LOG_DEBUGF("cli.c", "arg port=%s", args->port)
|
||||||
|
LOG_DEBUGF("cli.c", "arg credentials=%s", args->credentials)
|
||||||
|
LOG_DEBUGF("cli.c", "arg b64credentials=%s", args->b64credentials)
|
||||||
|
LOG_DEBUGF("cli.c", "arg index_count=%d", args->index_count)
|
||||||
|
for (int i = 0; i < args->index_count; i++) {
|
||||||
|
LOG_DEBUGF("cli.c", "arg indices[%d]=%s", i, args->indices[i])
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,5 +303,3 @@ web_args_t *web_args_create() {
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,14 @@ 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;
|
||||||
|
const char *tesseract_path;
|
||||||
} 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 +52,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
|
||||||
|
|||||||
11
src/ctx.h
11
src/ctx.h
@@ -17,6 +17,8 @@ struct {
|
|||||||
float tn_qscale;
|
float tn_qscale;
|
||||||
int depth;
|
int depth;
|
||||||
archive_mode_t archive_mode;
|
archive_mode_t archive_mode;
|
||||||
|
int verbose;
|
||||||
|
int very_verbose;
|
||||||
|
|
||||||
size_t stat_tn_size;
|
size_t stat_tn_size;
|
||||||
size_t stat_index_size;
|
size_t stat_index_size;
|
||||||
@@ -25,10 +27,16 @@ struct {
|
|||||||
GHashTable *copy_table;
|
GHashTable *copy_table;
|
||||||
|
|
||||||
pthread_mutex_t mupdf_mu;
|
pthread_mutex_t mupdf_mu;
|
||||||
|
char * tesseract_lang;
|
||||||
|
char * tesseract_path;
|
||||||
} ScanCtx;
|
} ScanCtx;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
int verbose;
|
||||||
|
int very_verbose;
|
||||||
|
int no_color;
|
||||||
|
} LogCtx;
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
|
||||||
struct {
|
struct {
|
||||||
char *es_url;
|
char *es_url;
|
||||||
int batch_size;
|
int batch_size;
|
||||||
@@ -40,7 +48,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,15 +129,14 @@ void elastic_flush() {
|
|||||||
Indexer->queued = 0;
|
Indexer->queued = 0;
|
||||||
|
|
||||||
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);
|
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,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 +279,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();
|
||||||
|
|
||||||
@@ -229,7 +252,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 +273,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,8 +294,7 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Invalid meta key (corrupt index): %x\n", key);
|
LOG_FATALF("serialize.c", "Invalid meta key (corrupt index): %x", key)
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
key = getc(file);
|
key = getc(file);
|
||||||
@@ -276,6 +307,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);
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ store_t *store_create(char *path) {
|
|||||||
mdb_env_create(&store->env);
|
mdb_env_create(&store->env);
|
||||||
|
|
||||||
int open_ret = mdb_env_open(store->env,
|
int open_ret = mdb_env_open(store->env,
|
||||||
path,
|
path,
|
||||||
MDB_WRITEMAP | MDB_MAPASYNC,
|
MDB_WRITEMAP | MDB_MAPASYNC,
|
||||||
S_IRUSR | S_IWUSR
|
S_IRUSR | S_IWUSR
|
||||||
);
|
);
|
||||||
|
|
||||||
if (open_ret != 0) {
|
if (open_ret != 0) {
|
||||||
@@ -42,6 +42,12 @@ void store_destroy(store_t *store) {
|
|||||||
|
|
||||||
void store_write(store_t *store, char *key, size_t key_len, char *buf, size_t buf_len) {
|
void store_write(store_t *store, char *key, size_t key_len, char *buf, size_t buf_len) {
|
||||||
|
|
||||||
|
if (LogCtx.very_verbose) {
|
||||||
|
char uuid_str[UUID_STR_LEN];
|
||||||
|
uuid_unparse((unsigned char *) key, uuid_str);
|
||||||
|
LOG_DEBUGF("store.c", "Store write {%s} %lu bytes", uuid_str, buf_len)
|
||||||
|
}
|
||||||
|
|
||||||
MDB_val mdb_key;
|
MDB_val mdb_key;
|
||||||
mdb_key.mv_data = key;
|
mdb_key.mv_data = key;
|
||||||
mdb_key.mv_size = key_len;
|
mdb_key.mv_size = key_len;
|
||||||
@@ -68,6 +74,8 @@ void store_write(store_t *store, char *key, size_t key_len, char *buf, size_t bu
|
|||||||
mdb_env_set_mapsize(store->env, store->size);
|
mdb_env_set_mapsize(store->env, store->size);
|
||||||
mdb_txn_begin(store->env, NULL, 0, &txn);
|
mdb_txn_begin(store->env, NULL, 0, &txn);
|
||||||
put_ret = mdb_put(txn, store->dbi, &mdb_key, &mdb_value, 0);
|
put_ret = mdb_put(txn, store->dbi, &mdb_key, &mdb_value, 0);
|
||||||
|
|
||||||
|
LOG_INFOF("store.c", "Updated mdb mapsize to %lu bytes", store->size)
|
||||||
}
|
}
|
||||||
|
|
||||||
mdb_txn_commit(txn);
|
mdb_txn_commit(txn);
|
||||||
|
|||||||
99
src/log.c
Normal file
99
src/log.c
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
const char *log_colors[] = {
|
||||||
|
"\033[34m", "\033[01;34m", "\033[0m",
|
||||||
|
"\033[01;33m", "\033[31m", "\033[01;31m"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *log_levels[] = {
|
||||||
|
"DEBUG", "INFO", "WARNING", "ERROR", "FATAL"
|
||||||
|
};
|
||||||
|
|
||||||
|
void sist_logf(char *filepath, int level, char *format, ...) {
|
||||||
|
|
||||||
|
static int is_tty = -1;
|
||||||
|
if (is_tty == -1) {
|
||||||
|
is_tty = isatty(STDERR_FILENO);
|
||||||
|
}
|
||||||
|
|
||||||
|
char log_str[LOG_MAX_LENGTH];
|
||||||
|
|
||||||
|
unsigned long long pid = (unsigned long long) pthread_self();
|
||||||
|
|
||||||
|
char datetime[32];
|
||||||
|
time_t t;
|
||||||
|
struct tm result;
|
||||||
|
t = time(NULL);
|
||||||
|
localtime_r(&t, &result);
|
||||||
|
strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", &result);
|
||||||
|
|
||||||
|
int log_len;
|
||||||
|
if (is_tty) {
|
||||||
|
log_len = snprintf(
|
||||||
|
log_str, sizeof(log_str),
|
||||||
|
"\033[%dm[%04X]%s [%s] [%s %s] ",
|
||||||
|
31 + ((unsigned int) (pid)) % 7, pid, log_colors[level],
|
||||||
|
datetime, log_levels[level], filepath
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
log_len = snprintf(
|
||||||
|
log_str, sizeof(log_str),
|
||||||
|
"[%04X] [%s] [%s %s] ",
|
||||||
|
pid, datetime, log_levels[level], filepath
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
size_t maxsize = sizeof(log_str) - log_len;
|
||||||
|
log_len += vsnprintf(log_str + log_len, maxsize, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (is_tty) {
|
||||||
|
log_len += sprintf(log_str + log_len, "\033[0m\n");
|
||||||
|
} else {
|
||||||
|
*(log_str + log_len) = '\n';
|
||||||
|
log_len += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
write(STDERR_FILENO, log_str, log_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sist_log(char *filepath, int level, char *str) {
|
||||||
|
|
||||||
|
static int is_tty = -1;
|
||||||
|
if (is_tty == -1) {
|
||||||
|
is_tty = isatty(STDERR_FILENO);
|
||||||
|
}
|
||||||
|
|
||||||
|
char log_str[LOG_MAX_LENGTH];
|
||||||
|
|
||||||
|
unsigned long long pid = (unsigned long long) pthread_self();
|
||||||
|
|
||||||
|
char datetime[32];
|
||||||
|
time_t t;
|
||||||
|
struct tm result;
|
||||||
|
t = time(NULL);
|
||||||
|
localtime_r(&t, &result);
|
||||||
|
strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", &result);
|
||||||
|
|
||||||
|
int log_len;
|
||||||
|
if (is_tty) {
|
||||||
|
log_len = snprintf(
|
||||||
|
log_str, sizeof(log_str),
|
||||||
|
"\033[%dm[%04X]%s [%s] [%s %s] %s \033[0m\n",
|
||||||
|
31 + ((unsigned int) (pid)) % 7, pid, log_colors[level],
|
||||||
|
datetime, log_levels[level], filepath,
|
||||||
|
str
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
log_len = snprintf(
|
||||||
|
log_str, sizeof(log_str),
|
||||||
|
"[%04X] [%s] [%s %s] %s \n",
|
||||||
|
pid, datetime, log_levels[level], filepath,
|
||||||
|
str
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
write(STDERR_FILENO, log_str, log_len);
|
||||||
|
}
|
||||||
45
src/log.h
Normal file
45
src/log.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#ifndef SIST2_LOG_H
|
||||||
|
#define SIST2_LOG_H
|
||||||
|
|
||||||
|
#define LOG_MAX_LENGTH 8192
|
||||||
|
|
||||||
|
#define SIST_DEBUG 0
|
||||||
|
#define SIST_INFO 1
|
||||||
|
#define SIST_WARNING 2
|
||||||
|
#define SIST_ERROR 3
|
||||||
|
#define SIST_FATAL 4
|
||||||
|
|
||||||
|
#define LOG_DEBUGF(filepath, fmt, ...) \
|
||||||
|
if (LogCtx.very_verbose) {sist_logf(filepath, SIST_DEBUG, fmt, __VA_ARGS__);}
|
||||||
|
#define LOG_DEBUG(filepath, str) \
|
||||||
|
if (LogCtx.very_verbose) {sist_log(filepath, SIST_DEBUG, str);}
|
||||||
|
|
||||||
|
#define LOG_INFOF(filepath, fmt, ...) \
|
||||||
|
if (LogCtx.verbose) {sist_logf(filepath, SIST_INFO, fmt, __VA_ARGS__);}
|
||||||
|
#define LOG_INFO(filepath, str) \
|
||||||
|
if (LogCtx.verbose) {sist_log(filepath, SIST_INFO, str);}
|
||||||
|
|
||||||
|
#define LOG_WARNINGF(filepath, fmt, ...) \
|
||||||
|
if (LogCtx.verbose) {sist_logf(filepath, SIST_WARNING, fmt, __VA_ARGS__);}
|
||||||
|
#define LOG_WARNING(filepath, str) \
|
||||||
|
if (LogCtx.verbose) {sist_log(filepath, SIST_WARNING, str);}
|
||||||
|
|
||||||
|
#define LOG_ERRORF(filepath, fmt, ...) \
|
||||||
|
if (LogCtx.verbose) {sist_logf(filepath, SIST_ERROR, fmt, __VA_ARGS__);}
|
||||||
|
#define LOG_ERROR(filepath, str) \
|
||||||
|
if (LogCtx.verbose) {sist_log(filepath, SIST_ERROR, str);}
|
||||||
|
|
||||||
|
#define LOG_FATALF(filepath, fmt, ...) \
|
||||||
|
sist_logf(filepath, SIST_FATAL, fmt, __VA_ARGS__);\
|
||||||
|
exit(-1);
|
||||||
|
#define LOG_FATAL(filepath, str) \
|
||||||
|
sist_log(filepath, SIST_FATAL, str);\
|
||||||
|
exit(-1);
|
||||||
|
|
||||||
|
#include "src/sist.h"
|
||||||
|
|
||||||
|
void sist_logf(char *filepath, int level, char *format, ...);
|
||||||
|
|
||||||
|
void sist_log(char *filepath, int level, char *str);
|
||||||
|
|
||||||
|
#endif
|
||||||
63
src/main.c
63
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.11";
|
static const char *const Version = "1.2.9";
|
||||||
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,29 +29,13 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void scan_print_header() {
|
void scan_print_header() {
|
||||||
printf("sist2 V%s\n", Version);
|
LOG_INFOF("main.c", "sist2 v%s", Version)
|
||||||
printf("---------------------\n");
|
|
||||||
printf("threads\t\t\t%d\n", ScanCtx.threads);
|
|
||||||
printf("tn_qscale\t\t%.1f/31.0\n", ScanCtx.tn_qscale);
|
|
||||||
|
|
||||||
if (ScanCtx.tn_size > 0) {
|
|
||||||
printf("tn_size\t\t\t%dpx\n", ScanCtx.tn_size);
|
|
||||||
} else {
|
|
||||||
printf("tn_size\t\t\tdisabled\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ScanCtx.content_size > 0) {
|
|
||||||
printf("content_size\t\t%d B\n", ScanCtx.content_size);
|
|
||||||
} else {
|
|
||||||
printf("content_size\t\t\tdisabled\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("output\t\t\t%s\n", ScanCtx.index.path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sist2_scan(scan_args_t *args) {
|
void sist2_scan(scan_args_t *args) {
|
||||||
@@ -71,7 +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_path = args->tesseract_path;
|
||||||
|
|
||||||
init_dir(ScanCtx.index.path);
|
init_dir(ScanCtx.index.path);
|
||||||
|
|
||||||
@@ -139,8 +120,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;
|
||||||
@@ -154,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,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);
|
||||||
@@ -215,18 +198,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;
|
||||||
|
|
||||||
@@ -236,6 +215,8 @@ int main(int argc, const char *argv[]) {
|
|||||||
OPT_HELP(),
|
OPT_HELP(),
|
||||||
|
|
||||||
OPT_BOOLEAN('v', "version", &arg_version, "Show version and exit"),
|
OPT_BOOLEAN('v', "version", &arg_version, "Show version and exit"),
|
||||||
|
OPT_BOOLEAN(0, "verbose", &LogCtx.verbose, "Turn on logging"),
|
||||||
|
OPT_BOOLEAN(0, "very-verbose", &LogCtx.very_verbose, "Turn on debug messages"),
|
||||||
|
|
||||||
OPT_GROUP("Scan options"),
|
OPT_GROUP("Scan options"),
|
||||||
OPT_INTEGER('t', "threads", &scan_args->threads, "Number of threads. DEFAULT=1"),
|
OPT_INTEGER('t', "threads", &scan_args->threads, "Number of threads. DEFAULT=1"),
|
||||||
@@ -255,8 +236,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."),
|
||||||
@@ -270,7 +252,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(),
|
||||||
};
|
};
|
||||||
@@ -285,10 +266,12 @@ int main(int argc, const char *argv[]) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
if (LogCtx.very_verbose != 0) {
|
||||||
|
LogCtx.verbose = 1;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
@@ -303,7 +286,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);
|
||||||
@@ -321,7 +303,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);
|
||||||
@@ -331,10 +312,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,18 +67,24 @@ void parse_archive(vfile_t *f, document_t *doc) {
|
|||||||
struct archive *a;
|
struct archive *a;
|
||||||
struct archive_entry *entry;
|
struct archive_entry *entry;
|
||||||
|
|
||||||
a = archive_read_new();
|
|
||||||
|
|
||||||
archive_read_support_filter_all(a);
|
|
||||||
archive_read_support_format_all(a);
|
|
||||||
|
|
||||||
arc_data_f data;
|
arc_data_f data;
|
||||||
data.f = f;
|
data.f = f;
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
if (data.f->is_fs_file) {
|
if (data.f->is_fs_file) {
|
||||||
|
|
||||||
|
a = archive_read_new();
|
||||||
|
archive_read_support_filter_all(a);
|
||||||
|
archive_read_support_format_all(a);
|
||||||
|
|
||||||
ret = archive_read_open_filename(a, doc->filepath, ARC_BUF_SIZE);
|
ret = archive_read_open_filename(a, doc->filepath, ARC_BUF_SIZE);
|
||||||
} else if (ScanCtx.archive_mode == ARC_MODE_RECURSE) {
|
} else if (ScanCtx.archive_mode == ARC_MODE_RECURSE) {
|
||||||
|
|
||||||
|
a = archive_read_new();
|
||||||
|
archive_read_support_filter_all(a);
|
||||||
|
archive_read_support_format_all(a);
|
||||||
|
|
||||||
ret = archive_read_open(
|
ret = archive_read_open(
|
||||||
a, &data,
|
a, &data,
|
||||||
vfile_open_callback,
|
vfile_open_callback,
|
||||||
@@ -86,12 +92,11 @@ void parse_archive(vfile_t *f, document_t *doc) {
|
|||||||
vfile_close_callback
|
vfile_close_callback
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
archive_read_free(a);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != ARCHIVE_OK) {
|
if (ret != ARCHIVE_OK) {
|
||||||
fprintf(stderr, "OPEN[%d]:%s %s\n", ret, archive_error_string(a), doc->filepath);
|
LOG_ERRORF(doc->filepath, "(arc.c) [%d] %s", ret, archive_error_string(a))
|
||||||
archive_read_free(a);
|
archive_read_free(a);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,20 @@
|
|||||||
#include "doc.h"
|
#include "doc.h"
|
||||||
|
#include "src/ctx.h"
|
||||||
|
|
||||||
static void dumpText(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);
|
||||||
@@ -17,10 +28,14 @@ static void dumpText(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) {
|
||||||
dumpText(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
|
||||||
@@ -50,30 +65,40 @@ int should_read_part(opcPart part) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_part(opcContainer *c, dyn_buffer_t *buf, opcPart part) {
|
__always_inline
|
||||||
|
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) {
|
||||||
//todo verbose
|
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) {
|
||||||
dumpText(&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) {
|
||||||
|
|
||||||
|
if (mem == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
opcContainer *c = opcContainerOpenMem(mem, mem_len, OPC_OPEN_READ_ONLY, NULL);
|
opcContainer *c = opcContainerOpenMem(mem, mem_len, OPC_OPEN_READ_ONLY, NULL);
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
//todo verbose
|
LOG_ERROR(doc->filepath, "(doc.c) Couldn't open document with opcContainerOpenMem()");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,17 +107,23 @@ 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);
|
int ret = read_part(c, &buf, part, doc);
|
||||||
|
if (ret != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while ((part = opcPartGetNext(c, part)));
|
} while ((part = opcPartGetNext(c, part)));
|
||||||
|
|
||||||
opcContainerClose(c, OPC_CLOSE_NOW);
|
opcContainerClose(c, OPC_CLOSE_NOW);
|
||||||
dyn_buffer_write_char(&buf, '\0');
|
|
||||||
|
|
||||||
meta_line_t *meta = malloc(sizeof(meta_line_t) + buf.cur);
|
if (buf.cur > 0) {
|
||||||
meta->key = MetaContent;
|
dyn_buffer_write_char(&buf, '\0');
|
||||||
strcpy(meta->strval, buf.buf);
|
|
||||||
APPEND_META(doc, meta)
|
meta_line_t *meta = malloc(sizeof(meta_line_t) + buf.cur);
|
||||||
|
meta->key = MetaContent;
|
||||||
|
strcpy(meta->strval, buf.buf);
|
||||||
|
APPEND_META(doc, meta)
|
||||||
|
}
|
||||||
|
|
||||||
dyn_buffer_destroy(&buf);
|
dyn_buffer_destroy(&buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
|||||||
FT_Face face;
|
FT_Face face;
|
||||||
FT_Error err = FT_New_Memory_Face(ft_lib, (unsigned char *) buf, buf_len, 0, &face);
|
FT_Error err = FT_New_Memory_Face(ft_lib, (unsigned char *) buf, buf_len, 0, &face);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_ERRORF(doc->filepath, "(font.c) FT_New_Memory_Face() returned error code [%d] %s", err, ft_error_string(err));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,6 +177,7 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
|||||||
|
|
||||||
err = FT_Set_Pixel_Sizes(face, 0, pixel);
|
err = FT_Set_Pixel_Sizes(face, 0, pixel);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "(font.c) FT_Set_Pixel_Sizes() returned error code [%d] %s", err, ft_error_string(err))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +196,7 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
|||||||
c = c >= 'a' && c <= 'z' ? c - 32 : c + 32;
|
c = c >= 'a' && c <= 'z' ? c - 32 : c + 32;
|
||||||
err = FT_Load_Char(face, c, FT_LOAD_NO_HINTING | FT_LOAD_RENDER);
|
err = FT_Load_Char(face, c, FT_LOAD_NO_HINTING | FT_LOAD_RENDER);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "(font.c) FT_Load_Char() returned error code [%d] %s", err, ft_error_string(err));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ AVFrame *scale_frame(const AVCodecContext *decoder, const AVFrame *frame, int si
|
|||||||
return scaled_frame;
|
return scaled_frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int stream_idx) {
|
__always_inline
|
||||||
|
AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int stream_idx, document_t *doc) {
|
||||||
AVFrame *frame = av_frame_alloc();
|
AVFrame *frame = av_frame_alloc();
|
||||||
|
|
||||||
AVPacket avPacket;
|
AVPacket avPacket;
|
||||||
@@ -90,9 +91,12 @@ AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int st
|
|||||||
int read_frame_ret = av_read_frame(pFormatCtx, &avPacket);
|
int read_frame_ret = av_read_frame(pFormatCtx, &avPacket);
|
||||||
|
|
||||||
if (read_frame_ret != 0) {
|
if (read_frame_ret != 0) {
|
||||||
// if (read_frame_ret != AVERROR_EOF) {
|
if (read_frame_ret != AVERROR_EOF) {
|
||||||
// fprintf(stderr, "Error reading frame: %d\n", read_frame_ret);
|
LOG_WARNINGF(doc->filepath,
|
||||||
// }
|
"(media.c) avcodec_read_frame() returned error code [%d] %s",
|
||||||
|
read_frame_ret, av_err2str(read_frame_ret)
|
||||||
|
)
|
||||||
|
}
|
||||||
av_frame_free(&frame);
|
av_frame_free(&frame);
|
||||||
av_packet_unref(&avPacket);
|
av_packet_unref(&avPacket);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -109,7 +113,10 @@ AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int st
|
|||||||
// Feed it to decoder
|
// Feed it to decoder
|
||||||
int decode_ret = avcodec_send_packet(decoder, &avPacket);
|
int decode_ret = avcodec_send_packet(decoder, &avPacket);
|
||||||
if (decode_ret != 0) {
|
if (decode_ret != 0) {
|
||||||
printf("Error decoding frame: %s\n", av_err2str(decode_ret));
|
LOG_WARNINGF(doc->filepath,
|
||||||
|
"(media.c) avcodec_send_packet() returned error code [%d] %s",
|
||||||
|
decode_ret, av_err2str(decode_ret)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
av_packet_unref(&avPacket);
|
av_packet_unref(&avPacket);
|
||||||
receive_ret = avcodec_receive_frame(decoder, frame);
|
receive_ret = avcodec_receive_frame(decoder, frame);
|
||||||
@@ -120,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); \
|
||||||
@@ -152,7 +160,8 @@ void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
void append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *doc, int include_audio_tags, int is_video) {
|
void
|
||||||
|
append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *doc, int include_audio_tags, int is_video) {
|
||||||
|
|
||||||
if (is_video) {
|
if (is_video) {
|
||||||
meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
|
meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
|
||||||
@@ -184,6 +193,24 @@ void append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *
|
|||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,7 +286,7 @@ void parse_media(AVFormatContext *pFormatCtx, document_t *doc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AVFrame *frame = read_frame(pFormatCtx, decoder, video_stream);
|
AVFrame *frame = read_frame(pFormatCtx, decoder, video_stream, doc);
|
||||||
if (frame == NULL) {
|
if (frame == NULL) {
|
||||||
avcodec_free_context(&decoder);
|
avcodec_free_context(&decoder);
|
||||||
avformat_close_input(&pFormatCtx);
|
avformat_close_input(&pFormatCtx);
|
||||||
@@ -308,12 +335,14 @@ void parse_media_filename(const char *filepath, document_t *doc) {
|
|||||||
|
|
||||||
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
||||||
if (pFormatCtx == NULL) {
|
if (pFormatCtx == NULL) {
|
||||||
fprintf(stderr, "Could not allocate AVFormatContext! %s \n", filepath);
|
LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int res = avformat_open_input(&pFormatCtx, filepath, NULL, NULL);
|
int res = avformat_open_input(&pFormatCtx, filepath, NULL, NULL);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
fprintf(stderr, "media error: %s %s\n", filepath, av_err2str(res));
|
LOG_ERRORF(doc->filepath, "(media.c) avformat_open_input() returned [%d] %s", res, av_err2str(res))
|
||||||
|
avformat_close_input(&pFormatCtx);
|
||||||
|
avformat_free_context(pFormatCtx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +365,7 @@ void parse_media_vfile(struct vfile *f, document_t *doc) {
|
|||||||
|
|
||||||
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
||||||
if (pFormatCtx == NULL) {
|
if (pFormatCtx == NULL) {
|
||||||
fprintf(stderr, "Could not allocate AVFormatContext! %s \n", f->filepath);
|
LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,13 +378,22 @@ void parse_media_vfile(struct vfile *f, document_t *doc) {
|
|||||||
int res = avformat_open_input(&pFormatCtx, "", NULL, NULL);
|
int res = avformat_open_input(&pFormatCtx, "", NULL, NULL);
|
||||||
if (res == -5) {
|
if (res == -5) {
|
||||||
// Tried to parse media that requires seek
|
// Tried to parse media that requires seek
|
||||||
|
av_free(io_ctx->buffer);
|
||||||
|
avio_context_free(&io_ctx);
|
||||||
|
avformat_close_input(&pFormatCtx);
|
||||||
|
avformat_free_context(pFormatCtx);
|
||||||
return;
|
return;
|
||||||
} else if(res < 0) {
|
} else if (res < 0) {
|
||||||
fprintf(stderr, "media error: %s %s\n", f->filepath, av_err2str(res));
|
LOG_ERRORF(doc->filepath, "(media.c) avformat_open_input() returned [%d] %s", res, av_err2str(res))
|
||||||
|
av_free(io_ctx->buffer);
|
||||||
|
avio_context_free(&io_ctx);
|
||||||
|
avformat_close_input(&pFormatCtx);
|
||||||
|
avformat_free_context(pFormatCtx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_media(pFormatCtx, doc);
|
parse_media(pFormatCtx, doc);
|
||||||
av_free(io_ctx);
|
av_free(io_ctx->buffer);
|
||||||
|
avio_context_free(&io_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1193,6 +1193,8 @@ g_hash_table_insert(ext_table, "srt", (gpointer)text_plain);
|
|||||||
g_hash_table_insert(ext_table, "nfo", (gpointer)text_plain);
|
g_hash_table_insert(ext_table, "nfo", (gpointer)text_plain);
|
||||||
g_hash_table_insert(ext_table, "sfv", (gpointer)text_plain);
|
g_hash_table_insert(ext_table, "sfv", (gpointer)text_plain);
|
||||||
g_hash_table_insert(ext_table, "m3u", (gpointer)text_plain);
|
g_hash_table_insert(ext_table, "m3u", (gpointer)text_plain);
|
||||||
|
g_hash_table_insert(ext_table, "csv", (gpointer)text_plain);
|
||||||
|
g_hash_table_insert(ext_table, "eml", (gpointer)text_plain);
|
||||||
g_hash_table_insert(ext_table, "rt", (gpointer)text_richtext);
|
g_hash_table_insert(ext_table, "rt", (gpointer)text_richtext);
|
||||||
g_hash_table_insert(ext_table, "rtf", (gpointer)text_richtext);
|
g_hash_table_insert(ext_table, "rtf", (gpointer)text_richtext);
|
||||||
g_hash_table_insert(ext_table, "rtx", (gpointer)text_richtext);
|
g_hash_table_insert(ext_table, "rtx", (gpointer)text_richtext);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include <src/ctx.h>
|
|
||||||
#include "src/sist.h"
|
#include "src/sist.h"
|
||||||
#include "src/ctx.h"
|
#include "src/ctx.h"
|
||||||
|
|
||||||
@@ -9,8 +8,7 @@ int fs_read(struct vfile *f, void *buf, size_t size) {
|
|||||||
if (f->fd == -1) {
|
if (f->fd == -1) {
|
||||||
f->fd = open(f->filepath, O_RDONLY);
|
f->fd = open(f->filepath, O_RDONLY);
|
||||||
if (f->fd == -1) {
|
if (f->fd == -1) {
|
||||||
perror("open");
|
LOG_ERRORF(f->filepath, "open(): [%d] %s", errno, strerror(errno))
|
||||||
printf("%s\n", f->filepath);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +37,7 @@ void *read_all(parse_job_t *job, const char *buf, int bytes_read) {
|
|||||||
|
|
||||||
int ret = job->vfile.read(&job->vfile, full_buf + bytes_read, job->info.st_size - bytes_read);
|
int ret = job->vfile.read(&job->vfile, full_buf + bytes_read, job->info.st_size - bytes_read);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
perror("read");
|
LOG_ERRORF(job->filepath, "read(): [%d] %s", errno, strerror(errno))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,6 +73,12 @@ void parse(void *arg) {
|
|||||||
uuid_generate(doc.uuid);
|
uuid_generate(doc.uuid);
|
||||||
char *buf[PARSE_BUF_SIZE];
|
char *buf[PARSE_BUF_SIZE];
|
||||||
|
|
||||||
|
if (LogCtx.very_verbose) {
|
||||||
|
char uuid_str[UUID_STR_LEN];
|
||||||
|
uuid_unparse(doc.uuid, uuid_str);
|
||||||
|
LOG_DEBUGF(job->filepath, "Starting parse job {%s}", uuid_str)
|
||||||
|
}
|
||||||
|
|
||||||
if (job->info.st_size == 0) {
|
if (job->info.st_size == 0) {
|
||||||
doc.mime = MIME_EMPTY;
|
doc.mime = MIME_EMPTY;
|
||||||
} else if (*(job->filepath + job->ext) != '\0' && (job->ext - job->base != 1)) {
|
} else if (*(job->filepath + job->ext) != '\0' && (job->ext - job->base != 1)) {
|
||||||
@@ -87,6 +91,7 @@ void parse(void *arg) {
|
|||||||
// Get mime type with libmagic
|
// Get mime type with libmagic
|
||||||
bytes_read = job->vfile.read(&job->vfile, buf, PARSE_BUF_SIZE);
|
bytes_read = job->vfile.read(&job->vfile, buf, PARSE_BUF_SIZE);
|
||||||
if (bytes_read == -1) {
|
if (bytes_read == -1) {
|
||||||
|
LOG_WARNINGF(job->filepath, "read() Error: %s", strerror(errno))
|
||||||
CLOSE_FILE(job->vfile)
|
CLOSE_FILE(job->vfile)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -95,7 +100,7 @@ void parse(void *arg) {
|
|||||||
if (magic_mime_str != NULL) {
|
if (magic_mime_str != NULL) {
|
||||||
doc.mime = mime_get_mime_by_string(ScanCtx.mime_table, magic_mime_str);
|
doc.mime = mime_get_mime_by_string(ScanCtx.mime_table, magic_mime_str);
|
||||||
if (doc.mime == 0) {
|
if (doc.mime == 0) {
|
||||||
fprintf(stderr, "Couldn't find mime %s, %s\n", magic_mime_str, job->filepath + job->base);
|
LOG_WARNINGF(job->filepath, "Couldn't find mime %s", magic_mime_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -14,6 +18,7 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
|||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
fz_drop_page(ctx, cover);
|
fz_drop_page(ctx, cover);
|
||||||
|
LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +57,7 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
|||||||
err = ctx->error.errcode;
|
err = ctx->error.errcode;
|
||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
fz_drop_page(ctx, cover);
|
fz_drop_page(ctx, cover);
|
||||||
fz_drop_pixmap(ctx, pixmap);
|
fz_drop_pixmap(ctx, pixmap);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -76,6 +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)
|
||||||
fz_drop_page(ctx, cover);
|
fz_drop_page(ctx, cover);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -83,14 +91,22 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) {
|
|||||||
return cover;
|
return cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fz_noop_callback(__attribute__((unused)) void *user, __attribute__((unused)) const char *message) {}
|
void fz_err_callback(void *user, UNUSED(const char *message)) {
|
||||||
|
if (LogCtx.verbose) {
|
||||||
|
document_t *doc = (document_t *) user;
|
||||||
|
LOG_WARNINGF(doc->filepath, "FZ: %s", message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__always_inline
|
||||||
void init_ctx(fz_context *ctx) {
|
void init_ctx(fz_context *ctx, document_t *doc) {
|
||||||
fz_disable_icc(ctx);
|
fz_disable_icc(ctx);
|
||||||
fz_register_document_handlers(ctx);
|
fz_register_document_handlers(ctx);
|
||||||
ctx->warn.print = fz_noop_callback;
|
|
||||||
ctx->error.print = fz_noop_callback;
|
ctx->warn.print_user = doc;
|
||||||
|
ctx->warn.print = fz_err_callback;
|
||||||
|
ctx->error.print_user = doc;
|
||||||
|
ctx->error.print = fz_err_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_stext_block(fz_stext_block *block, text_buffer_t *tex) {
|
int read_stext_block(fz_stext_block *block, text_buffer_t *tex) {
|
||||||
@@ -112,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, ScanCtx.tesseract_path, 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) {
|
||||||
@@ -125,7 +175,7 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
}
|
}
|
||||||
fz_context *ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
|
fz_context *ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
|
||||||
|
|
||||||
init_ctx(ctx);
|
init_ctx(ctx, doc);
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
@@ -171,6 +221,7 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
err = ctx->error.errcode;
|
err = ctx->error.errcode;
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
LOG_WARNINGF(doc->filepath, "fz_count_pages() returned error code [%d] %s", err, ctx->error.message)
|
||||||
fz_drop_stream(ctx, stream);
|
fz_drop_stream(ctx, stream);
|
||||||
fz_drop_document(ctx, fzdoc);
|
fz_drop_document(ctx, fzdoc);
|
||||||
fz_drop_context(ctx);
|
fz_drop_context(ctx);
|
||||||
@@ -197,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;
|
||||||
@@ -210,7 +261,8 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
|||||||
fz_catch(ctx)
|
fz_catch(ctx)
|
||||||
err = ctx->error.errcode;
|
err = ctx->error.errcode;
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
text_buffer_destroy(&text_buf);
|
LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
|
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);
|
||||||
@@ -221,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)
|
||||||
@@ -234,7 +295,8 @@ 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) {
|
||||||
text_buffer_destroy(&text_buf);
|
LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, ctx->error.message)
|
||||||
|
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);
|
||||||
@@ -245,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;
|
||||||
}
|
}
|
||||||
@@ -254,22 +316,21 @@ 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);
|
||||||
fz_drop_document(ctx, fzdoc);
|
fz_drop_document(ctx, fzdoc);
|
||||||
fz_drop_context(ctx);
|
fz_drop_context(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
18
src/sist.h
18
src/sist.h
@@ -2,6 +2,7 @@
|
|||||||
#define SIST_H
|
#define SIST_H
|
||||||
|
|
||||||
#define UUID_STR_LEN 37
|
#define UUID_STR_LEN 37
|
||||||
|
#define UNUSED(x) __attribute__((__unused__)) x
|
||||||
|
|
||||||
#include <glib-2.0/glib.h>
|
#include <glib-2.0/glib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -12,11 +13,11 @@
|
|||||||
#include <ftw.h>
|
#include <ftw.h>
|
||||||
#include <uuid.h>
|
#include <uuid.h>
|
||||||
#include <magic.h>
|
#include <magic.h>
|
||||||
#include <libavformat/avformat.h>
|
#include "libavformat/avformat.h"
|
||||||
#include <libswscale/swscale.h>
|
#include "libswscale/swscale.h"
|
||||||
#include <libswresample/swresample.h>
|
#include "libswresample/swresample.h"
|
||||||
#include <libavcodec/avcodec.h>
|
#include "libavcodec/avcodec.h"
|
||||||
#include <libavutil/imgutils.h>
|
#include "libavutil/imgutils.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <mupdf/fitz.h>
|
#include <mupdf/fitz.h>
|
||||||
#include <mupdf/pdf.h>
|
#include <mupdf/pdf.h>
|
||||||
@@ -32,15 +33,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"
|
||||||
|
|
||||||
@@ -59,14 +60,13 @@
|
|||||||
#include "parsing/arc.h"
|
#include "parsing/arc.h"
|
||||||
#include "parsing/doc.h"
|
#include "parsing/doc.h"
|
||||||
#include "cli.h"
|
#include "cli.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
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
10
src/tpool.c
10
src/tpool.c
@@ -136,6 +136,7 @@ static void *tpool_worker(void *arg) {
|
|||||||
pthread_mutex_unlock(&(pool->work_mutex));
|
pthread_mutex_unlock(&(pool->work_mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_INFO("tpool.c", "Executing cleaup function")
|
||||||
pool->cleanup_func();
|
pool->cleanup_func();
|
||||||
|
|
||||||
pthread_cond_signal(&(pool->working_cond));
|
pthread_cond_signal(&(pool->working_cond));
|
||||||
@@ -144,6 +145,7 @@ static void *tpool_worker(void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void tpool_wait(tpool_t *pool) {
|
void tpool_wait(tpool_t *pool) {
|
||||||
|
LOG_INFO("tpool.c", "Waiting for worker threads to finish")
|
||||||
pthread_mutex_lock(&(pool->work_mutex));
|
pthread_mutex_lock(&(pool->work_mutex));
|
||||||
while (1) {
|
while (1) {
|
||||||
if (pool->done_cnt < pool->work_cnt) {
|
if (pool->done_cnt < pool->work_cnt) {
|
||||||
@@ -159,6 +161,8 @@ void tpool_wait(tpool_t *pool) {
|
|||||||
}
|
}
|
||||||
progress_bar_print(1.0, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
|
progress_bar_print(1.0, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
|
||||||
pthread_mutex_unlock(&(pool->work_mutex));
|
pthread_mutex_unlock(&(pool->work_mutex));
|
||||||
|
|
||||||
|
LOG_INFO("tpool.c", "Worker threads finished")
|
||||||
}
|
}
|
||||||
|
|
||||||
void tpool_destroy(tpool_t *pool) {
|
void tpool_destroy(tpool_t *pool) {
|
||||||
@@ -166,6 +170,8 @@ void tpool_destroy(tpool_t *pool) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_INFO("tpool.c", "Destroying thread pool")
|
||||||
|
|
||||||
pthread_mutex_lock(&(pool->work_mutex));
|
pthread_mutex_lock(&(pool->work_mutex));
|
||||||
tpool_work_t *work = pool->work_head;
|
tpool_work_t *work = pool->work_head;
|
||||||
while (work != NULL) {
|
while (work != NULL) {
|
||||||
@@ -185,6 +191,8 @@ void tpool_destroy(tpool_t *pool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_INFO("tpool.c", "Final cleanup")
|
||||||
|
|
||||||
pthread_mutex_destroy(&(pool->work_mutex));
|
pthread_mutex_destroy(&(pool->work_mutex));
|
||||||
pthread_cond_destroy(&(pool->has_work_cond));
|
pthread_cond_destroy(&(pool->has_work_cond));
|
||||||
pthread_cond_destroy(&(pool->working_cond));
|
pthread_cond_destroy(&(pool->working_cond));
|
||||||
@@ -220,6 +228,8 @@ tpool_t *tpool_create(size_t thread_cnt, void cleanup_func()) {
|
|||||||
|
|
||||||
void tpool_start(tpool_t *pool) {
|
void tpool_start(tpool_t *pool) {
|
||||||
|
|
||||||
|
LOG_INFOF("tpool.c", "Starting thread pool with %d threads", pool->thread_cnt)
|
||||||
|
|
||||||
for (size_t i = 0; i < pool->thread_cnt; i++) {
|
for (size_t i = 0; i < pool->thread_cnt; i++) {
|
||||||
pthread_create(&pool->threads[i], NULL, tpool_worker, pool);
|
pthread_create(&pool->threads[i], NULL, tpool_worker, pool);
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/types.h
25
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,8 +31,22 @@ 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[6];
|
||||||
@@ -41,6 +55,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 +85,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 +92,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 {
|
||||||
|
|||||||
39
src/util.c
39
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
|
||||||
@@ -149,7 +154,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 +162,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,13 +172,12 @@ 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) {
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -320,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 >= (int)'!')
|
#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
|
||||||
|
|||||||
110
src/web/serve.c
110
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);
|
||||||
|
|
||||||
@@ -214,21 +214,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 +228,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 +246,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 +282,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 +308,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 +386,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 +421,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 +429,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,43 @@
|
|||||||
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 {
|
||||||
|
display: -ms-flexbox;
|
||||||
|
display: flex;
|
||||||
|
-ms-flex-align: start;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-container {
|
||||||
|
margin-left: 0.3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.path-line {
|
||||||
|
color: #BBB;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #00BCD4;
|
color: #00BCD4;
|
||||||
}
|
}
|
||||||
@@ -15,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;
|
||||||
@@ -23,8 +60,33 @@ 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;
|
background: #37474F !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item.sub-document {
|
||||||
|
border-top: 1px solid #646464 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sub-document .text-muted {
|
.sub-document .text-muted {
|
||||||
@@ -112,6 +174,9 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.file-title {
|
.file-title {
|
||||||
|
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;
|
||||||
|
|||||||
1
web/css/jquery.toast.min.css
vendored
Normal file
1
web/css/jquery.toast.min.css
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.jq-toast-wrap,.jq-toast-wrap *{margin:0;padding:0}.jq-toast-wrap{display:block;position:fixed;width:250px;pointer-events:none!important;letter-spacing:normal;z-index:9000!important}.jq-toast-wrap.bottom-left{bottom:20px;left:20px}.jq-toast-wrap.bottom-right{bottom:20px;right:40px}.jq-toast-wrap.top-left{top:20px;left:20px}.jq-toast-wrap.top-right{top:20px;right:40px}.jq-toast-single{display:block;width:100%;padding:10px;margin:0 0 5px;border-radius:4px;font-size:12px;font-family:arial,sans-serif;line-height:17px;position:relative;pointer-events:all!important;background-color:#444;color:#fff}.jq-toast-single h2{font-family:arial,sans-serif;font-size:14px;margin:0 0 7px;background:0 0;color:inherit;line-height:inherit;letter-spacing:normal}.jq-toast-single a{color:#eee;text-decoration:none;font-weight:700;border-bottom:1px solid #fff;padding-bottom:3px;font-size:12px}.jq-toast-single ul{margin:0 0 0 15px;background:0 0;padding:0}.jq-toast-single ul li{list-style-type:disc!important;line-height:17px;background:0 0;margin:0;padding:0;letter-spacing:normal}.close-jq-toast-single{position:absolute;top:3px;right:7px;font-size:14px;cursor:pointer}.jq-toast-loader{display:block;position:absolute;top:-2px;height:5px;width:0;left:0;border-radius:5px;background:red}.jq-toast-loaded{width:100%}.jq-has-icon{padding:10px 10px 10px 50px;background-repeat:no-repeat;background-position:10px}.jq-icon-info{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGwSURBVEhLtZa9SgNBEMc9sUxxRcoUKSzSWIhXpFMhhYWFhaBg4yPYiWCXZxBLERsLRS3EQkEfwCKdjWJAwSKCgoKCcudv4O5YLrt7EzgXhiU3/4+b2ckmwVjJSpKkQ6wAi4gwhT+z3wRBcEz0yjSseUTrcRyfsHsXmD0AmbHOC9Ii8VImnuXBPglHpQ5wwSVM7sNnTG7Za4JwDdCjxyAiH3nyA2mtaTJufiDZ5dCaqlItILh1NHatfN5skvjx9Z38m69CgzuXmZgVrPIGE763Jx9qKsRozWYw6xOHdER+nn2KkO+Bb+UV5CBN6WC6QtBgbRVozrahAbmm6HtUsgtPC19tFdxXZYBOfkbmFJ1VaHA1VAHjd0pp70oTZzvR+EVrx2Ygfdsq6eu55BHYR8hlcki+n+kERUFG8BrA0BwjeAv2M8WLQBtcy+SD6fNsmnB3AlBLrgTtVW1c2QN4bVWLATaIS60J2Du5y1TiJgjSBvFVZgTmwCU+dAZFoPxGEEs8nyHC9Bwe2GvEJv2WXZb0vjdyFT4Cxk3e/kIqlOGoVLwwPevpYHT+00T+hWwXDf4AJAOUqWcDhbwAAAAASUVORK5CYII=);background-color:#31708f;color:#d9edf7;border-color:#bce8f1}.jq-icon-warning{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGYSURBVEhL5ZSvTsNQFMbXZGICMYGYmJhAQIJAICYQPAACiSDB8AiICQQJT4CqQEwgJvYASAQCiZiYmJhAIBATCARJy+9rTsldd8sKu1M0+dLb057v6/lbq/2rK0mS/TRNj9cWNAKPYIJII7gIxCcQ51cvqID+GIEX8ASG4B1bK5gIZFeQfoJdEXOfgX4QAQg7kH2A65yQ87lyxb27sggkAzAuFhbbg1K2kgCkB1bVwyIR9m2L7PRPIhDUIXgGtyKw575yz3lTNs6X4JXnjV+LKM/m3MydnTbtOKIjtz6VhCBq4vSm3ncdrD2lk0VgUXSVKjVDJXJzijW1RQdsU7F77He8u68koNZTz8Oz5yGa6J3H3lZ0xYgXBK2QymlWWA+RWnYhskLBv2vmE+hBMCtbA7KX5drWyRT/2JsqZ2IvfB9Y4bWDNMFbJRFmC9E74SoS0CqulwjkC0+5bpcV1CZ8NMej4pjy0U+doDQsGyo1hzVJttIjhQ7GnBtRFN1UarUlH8F3xict+HY07rEzoUGPlWcjRFRr4/gChZgc3ZL2d8oAAAAASUVORK5CYII=);background-color:#8a6d3b;color:#fcf8e3;border-color:#faebcc}.jq-icon-error{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHOSURBVEhLrZa/SgNBEMZzh0WKCClSCKaIYOED+AAKeQQLG8HWztLCImBrYadgIdY+gIKNYkBFSwu7CAoqCgkkoGBI/E28PdbLZmeDLgzZzcx83/zZ2SSXC1j9fr+I1Hq93g2yxH4iwM1vkoBWAdxCmpzTxfkN2RcyZNaHFIkSo10+8kgxkXIURV5HGxTmFuc75B2RfQkpxHG8aAgaAFa0tAHqYFfQ7Iwe2yhODk8+J4C7yAoRTWI3w/4klGRgR4lO7Rpn9+gvMyWp+uxFh8+H+ARlgN1nJuJuQAYvNkEnwGFck18Er4q3egEc/oO+mhLdKgRyhdNFiacC0rlOCbhNVz4H9FnAYgDBvU3QIioZlJFLJtsoHYRDfiZoUyIxqCtRpVlANq0EU4dApjrtgezPFad5S19Wgjkc0hNVnuF4HjVA6C7QrSIbylB+oZe3aHgBsqlNqKYH48jXyJKMuAbiyVJ8KzaB3eRc0pg9VwQ4niFryI68qiOi3AbjwdsfnAtk0bCjTLJKr6mrD9g8iq/S/B81hguOMlQTnVyG40wAcjnmgsCNESDrjme7wfftP4P7SP4N3CJZdvzoNyGq2c/HWOXJGsvVg+RA/k2MC/wN6I2YA2Pt8GkAAAAASUVORK5CYII=);background-color:#a94442;color:#f2dede;border-color:#ebccd1}.jq-icon-success{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADsSURBVEhLY2AYBfQMgf///3P8+/evAIgvA/FsIF+BavYDDWMBGroaSMMBiE8VC7AZDrIFaMFnii3AZTjUgsUUWUDA8OdAH6iQbQEhw4HyGsPEcKBXBIC4ARhex4G4BsjmweU1soIFaGg/WtoFZRIZdEvIMhxkCCjXIVsATV6gFGACs4Rsw0EGgIIH3QJYJgHSARQZDrWAB+jawzgs+Q2UO49D7jnRSRGoEFRILcdmEMWGI0cm0JJ2QpYA1RDvcmzJEWhABhD/pqrL0S0CWuABKgnRki9lLseS7g2AlqwHWQSKH4oKLrILpRGhEQCw2LiRUIa4lwAAAABJRU5ErkJggg==);color:#dff0d8;background-color:#3c763d;border-color:#d6e9c6}
|
||||||
@@ -2,6 +2,42 @@
|
|||||||
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 {
|
||||||
|
display: -ms-flexbox;
|
||||||
|
display: flex;
|
||||||
|
-ms-flex-align: start;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-container {
|
||||||
|
margin-left: 0.3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.path-line {
|
||||||
|
color: #444;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
@@ -16,7 +52,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.sub-document {
|
.sub-document {
|
||||||
background: #AB47BC1F;
|
background: #AB47BC1F !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-brand {
|
.navbar-brand {
|
||||||
@@ -82,6 +118,9 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.file-title {
|
.file-title {
|
||||||
|
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;
|
||||||
|
|||||||
1
web/js/7_jquery.toast.min.js
vendored
Normal file
1
web/js/7_jquery.toast.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
101
web/js/dom.js
101
web/js/dom.js
@@ -113,7 +113,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 +121,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 +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"];
|
||||||
@@ -367,6 +417,12 @@ function createDocLine(hit) {
|
|||||||
const line = document.createElement("div");
|
const line = document.createElement("div");
|
||||||
line.setAttribute("class", "list-group-item flex-column align-items-start");
|
line.setAttribute("class", "list-group-item flex-column align-items-start");
|
||||||
|
|
||||||
|
if (hit["_source"].hasOwnProperty("parent")) {
|
||||||
|
line.classList.add("sub-document");
|
||||||
|
isSubDocument = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const infoButton = makeInfoButton(hit);
|
||||||
|
|
||||||
const title = makeTitle(hit);
|
const title = makeTitle(hit);
|
||||||
|
|
||||||
@@ -376,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);
|
||||||
|
|
||||||
@@ -396,8 +457,16 @@ function createDocLine(hit) {
|
|||||||
titleDiv.appendChild(contentDiv);
|
titleDiv.appendChild(contentDiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pathLine = document.createElement("div");
|
||||||
|
pathLine.setAttribute("class", "path-row");
|
||||||
|
|
||||||
|
let path = document.createElement("div");
|
||||||
|
path.setAttribute("class", "path-line");
|
||||||
|
path.setAttribute("title", hit["_source"]["path"] + "/");
|
||||||
|
path.appendChild(document.createTextNode(hit["_source"]["path"] + "/"));
|
||||||
|
|
||||||
let tagContainer = document.createElement("div");
|
let tagContainer = document.createElement("div");
|
||||||
tagContainer.setAttribute("class", "");
|
tagContainer.setAttribute("class", "tag-container");
|
||||||
|
|
||||||
for (let i = 0; i < tags.length; i++) {
|
for (let i = 0; i < tags.length; i++) {
|
||||||
tagContainer.appendChild(tags[i]);
|
tagContainer.appendChild(tags[i]);
|
||||||
@@ -409,7 +478,9 @@ function createDocLine(hit) {
|
|||||||
sizeTag.setAttribute("class", "text-muted");
|
sizeTag.setAttribute("class", "text-muted");
|
||||||
tagContainer.appendChild(sizeTag);
|
tagContainer.appendChild(sizeTag);
|
||||||
|
|
||||||
titleDiv.appendChild(tagContainer);
|
titleDiv.appendChild(pathLine);
|
||||||
|
pathLine.appendChild(path);
|
||||||
|
pathLine.appendChild(tagContainer);
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
@@ -428,8 +499,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;
|
||||||
}
|
}
|
||||||
@@ -476,8 +546,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);
|
||||||
|
|||||||
144
web/js/search.js
144
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;
|
||||||
@@ -19,6 +20,19 @@ if (localStorage.getItem("mode") === null) {
|
|||||||
mode = localStorage.getItem("mode")
|
mode = localStorage.getItem("mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showEsError() {
|
||||||
|
$.toast({
|
||||||
|
heading: "Elasticsearch connection error",
|
||||||
|
text: "sist2 web module encountered an error while connecting " +
|
||||||
|
"to Elasticsearch. See server logs for more information.",
|
||||||
|
stack: false,
|
||||||
|
bgColor: "#a94442",
|
||||||
|
textColor: "#f2dede",
|
||||||
|
position: 'bottom-right',
|
||||||
|
hideAfter: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
jQuery["jsonPost"] = function (url, data) {
|
jQuery["jsonPost"] = function (url, data) {
|
||||||
return jQuery.ajax({
|
return jQuery.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
@@ -26,6 +40,7 @@ jQuery["jsonPost"] = function (url, data) {
|
|||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
contentType: "application/json"
|
contentType: "application/json"
|
||||||
}).fail(err => {
|
}).fail(err => {
|
||||||
|
showEsError();
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -46,19 +61,35 @@ function toggleFuzzy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$.jsonPost("i").then(resp => {
|
$.jsonPost("i").then(resp => {
|
||||||
|
|
||||||
|
const urlIndices = (new URLSearchParams(location.search)).get("i");
|
||||||
|
|
||||||
resp["indices"].forEach(idx => {
|
resp["indices"].forEach(idx => {
|
||||||
const opt = $("<option>")
|
const opt = $("<option>")
|
||||||
.attr("value", idx.id)
|
.attr("value", idx.id)
|
||||||
.append(idx.name);
|
.append(idx.name);
|
||||||
if (!idx.name.includes("(nsfw)")) {
|
|
||||||
opt.attr("selected", !idx.name.includes("(nsfw)"));
|
if (urlIndices) {
|
||||||
|
if (urlIndices.split(",").indexOf(idx.name) !== -1) {
|
||||||
|
opt.attr("selected", true);
|
||||||
|
selectedIndices.push(idx.id);
|
||||||
|
}
|
||||||
|
} else if (!idx.name.includes("(nsfw)")) {
|
||||||
|
opt.attr("selected", true);
|
||||||
selectedIndices.push(idx.id);
|
selectedIndices.push(idx.id);
|
||||||
}
|
}
|
||||||
$("#indices").append(opt);
|
$("#indices").append(opt);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleTreeClick (tree) {
|
function getDocumentInfo(id) {
|
||||||
|
return $.getJSON("d/" + id).fail(e => {
|
||||||
|
console.log(e);
|
||||||
|
showEsError();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleTreeClick(tree) {
|
||||||
return (event, node, handler) => {
|
return (event, node, handler) => {
|
||||||
event.preventTreeDefault();
|
event.preventTreeDefault();
|
||||||
|
|
||||||
@@ -127,7 +158,7 @@ $.jsonPost("es", {
|
|||||||
|
|
||||||
function leafTag(tag) {
|
function leafTag(tag) {
|
||||||
const tokens = tag.split(".");
|
const tokens = tag.split(".");
|
||||||
return tokens[tokens.length-1]
|
return tokens[tokens.length - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tags tree
|
// Tags tree
|
||||||
@@ -145,8 +176,8 @@ $.jsonPost("es", {
|
|||||||
resp["aggregations"]["tags"]["buckets"]
|
resp["aggregations"]["tags"]["buckets"]
|
||||||
.sort((a, b) => a["key"].localeCompare(b["key"]))
|
.sort((a, b) => a["key"].localeCompare(b["key"]))
|
||||||
.forEach(bucket => {
|
.forEach(bucket => {
|
||||||
addTag(tagMap, bucket["key"], bucket["key"], bucket["doc_count"])
|
addTag(tagMap, bucket["key"], bucket["key"], bucket["doc_count"])
|
||||||
});
|
});
|
||||||
|
|
||||||
tagMap.push({"text": "All", "id": "any"});
|
tagMap.push({"text": "All", "id": "any"});
|
||||||
tagTree = new InspireTree({
|
tagTree = new InspireTree({
|
||||||
@@ -229,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 = [];
|
||||||
|
|
||||||
@@ -284,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";
|
||||||
@@ -332,9 +344,9 @@ 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: {
|
||||||
@@ -349,8 +361,9 @@ function search() {
|
|||||||
filter: filters
|
filter: filters
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sort: [
|
"sort": [
|
||||||
"_score"
|
{"_score": {"order": "desc"}},
|
||||||
|
{"_tie": {"order": "asc"}}
|
||||||
],
|
],
|
||||||
highlight: {
|
highlight: {
|
||||||
pre_tags: ["<mark>"],
|
pre_tags: ["<mark>"],
|
||||||
@@ -363,24 +376,41 @@ 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;
|
if (!after) {
|
||||||
insertHits(resultContainer, searchResult["hits"]["hits"]);
|
docCount = 0;
|
||||||
|
}
|
||||||
|
reachedEnd = hits.length !== SIZE;
|
||||||
|
insertHits(resultContainer, hits);
|
||||||
searchBusy = false;
|
searchBusy = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.11</span>
|
<span class="badge badge-pill version">v1.2.9</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