mirror of
https://github.com/TeamWiseFlow/wiseflow.git
synced 2025-01-23 10:50:25 +08:00
add web
This commit is contained in:
parent
15f0415323
commit
265e1c533a
14
client/.dockerignore
Normal file
14
client/.dockerignore
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
.git
|
||||||
|
.vscode
|
||||||
|
.dockerignore
|
||||||
|
.gitignore
|
||||||
|
.env
|
||||||
|
config
|
||||||
|
build
|
||||||
|
web/dist
|
||||||
|
web/node_modules
|
||||||
|
docker-compose.yaml
|
||||||
|
Dockerfile
|
||||||
|
README.md
|
||||||
|
backend/__pycache__
|
||||||
|
backend/AWtest
|
4
client/.gitignore
vendored
Normal file
4
client/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.env
|
||||||
|
.venv/
|
||||||
|
pb/pb_data/
|
||||||
|
backend/AWtest/
|
16
client/Dockerfile.api
Normal file
16
client/Dockerfile.api
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
FROM python:3.10-slim
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -yq tzdata && \
|
||||||
|
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||||
|
dpkg-reconfigure -f noninteractive tzdata
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY backend/requirements.txt requirements.txt
|
||||||
|
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
|
||||||
|
COPY backend ./
|
||||||
|
|
||||||
|
EXPOSE 7777
|
||||||
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7777"]
|
31
client/Dockerfile.web
Normal file
31
client/Dockerfile.web
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
FROM node:20-slim as builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY web ./
|
||||||
|
RUN npm install -g pnpm
|
||||||
|
RUN pnpm install
|
||||||
|
RUN pnpm build
|
||||||
|
|
||||||
|
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
ARG PB_VERSION=0.21.1
|
||||||
|
|
||||||
|
RUN apk add --no-cache unzip ca-certificates tzdata
|
||||||
|
|
||||||
|
# download and unzip PocketBase
|
||||||
|
ADD https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip /tmp/pb.zip
|
||||||
|
RUN unzip /tmp/pb.zip -d /pb/
|
||||||
|
|
||||||
|
RUN mkdir -p /pb
|
||||||
|
|
||||||
|
COPY ./pb/pb_migrations /pb/pb_migrations
|
||||||
|
COPY ./pb/pb_hooks /pb/pb_hooks
|
||||||
|
COPY --from=builder /app/dist /pb/pb_public
|
||||||
|
|
||||||
|
WORKDIR /pb
|
||||||
|
|
||||||
|
EXPOSE 8090
|
||||||
|
|
||||||
|
CMD ["/pb/pocketbase", "serve", "--http=0.0.0.0:8090"]
|
17
client/backend/requirements.txt
Normal file
17
client/backend/requirements.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
fastapi
|
||||||
|
pydantic
|
||||||
|
uvicorn
|
||||||
|
dashscope #optional(使用阿里灵积时安装)
|
||||||
|
volcengine #optional(使用火山翻译时安装)
|
||||||
|
python-docx
|
||||||
|
BCEmbedding==0.1.3
|
||||||
|
langchain==0.1.0
|
||||||
|
langchain-community==0.0.9
|
||||||
|
langchain-core==0.1.7
|
||||||
|
langsmith==0.0.77
|
||||||
|
# faiss-gpu for gpu environment
|
||||||
|
faiss-cpu # for cpu-only environment
|
||||||
|
pocketbase==0.10.0
|
||||||
|
gne
|
||||||
|
selenium
|
||||||
|
chardet
|
@ -1,3 +1,4 @@
|
|||||||
|
set -o allexport
|
||||||
source ../.env
|
source ../.env
|
||||||
|
set +o allexport
|
||||||
python background_task.py
|
python background_task.py
|
21
client/compose.yaml
Normal file
21
client/compose.yaml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
services:
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
dockerfile: Dockerfile.web
|
||||||
|
ports:
|
||||||
|
- 8090:8090
|
||||||
|
# env_file:
|
||||||
|
# - .env
|
||||||
|
volumes:
|
||||||
|
- ./pb/pb_data:/pb/pb_data
|
||||||
|
# - ./${PROJECT_DIR}:/pb/${PROJECT_DIR}
|
||||||
|
api:
|
||||||
|
build:
|
||||||
|
dockerfile: Dockerfile.api
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
ports:
|
||||||
|
- 7777:7777
|
||||||
|
volumes:
|
||||||
|
#- ./${PROJECT_DIR}:/app/${PROJECT_DIR}
|
||||||
|
- ${EMBEDDING_MODEL_PATH}:${EMBEDDING_MODEL_PATH}
|
@ -1,936 +0,0 @@
|
|||||||
## v0.22.3
|
|
||||||
|
|
||||||
- Fixed the z-index of the current admin dropdown on Safari ([#4492](https://github.com/pocketbase/pocketbase/issues/4492)).
|
|
||||||
|
|
||||||
- Fixed `OnAfterApiError` debug log `nil` error reference ([#4498](https://github.com/pocketbase/pocketbase/issues/4498)).
|
|
||||||
|
|
||||||
- Added the field name as part of the `@request.data.someRelField.*` join to handle the case when a collection has 2 or more relation fields pointing to the same place ([#4500](https://github.com/pocketbase/pocketbase/issues/4500)).
|
|
||||||
|
|
||||||
- Updated Go deps and bumped the min Go version in the GitHub release action to Go 1.22.1 since it comes with [some security fixes](https://github.com/golang/go/issues?q=milestone%3AGo1.22.1).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.22.2
|
|
||||||
|
|
||||||
- Fixed a small regression introduced with v0.22.0 that was causing some missing unknown fields to always return an error instead of applying the specific `nullifyMisingField` resolver option to the query.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.22.1
|
|
||||||
|
|
||||||
- Fixed Admin UI record and collection panels not reinitializing properly on browser back/forward navigation ([#4462](https://github.com/pocketbase/pocketbase/issues/4462)).
|
|
||||||
|
|
||||||
- Initialize `RecordAuthWithOAuth2Event.IsNewRecord` for the `OnRecordBeforeAuthWithOAuth2Request` hook ([#4437](https://github.com/pocketbase/pocketbase/discussions/4437)).
|
|
||||||
|
|
||||||
- Added error checks to the autogenerated Go migrations ([#4448](https://github.com/pocketbase/pocketbase/issues/4448)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.22.0
|
|
||||||
|
|
||||||
- Added Planning Center OAuth2 provider ([#4393](https://github.com/pocketbase/pocketbase/pull/4393); thanks @alxjsn).
|
|
||||||
|
|
||||||
- Admin UI improvements:
|
|
||||||
- Autosync collection changes across multiple open browser tabs.
|
|
||||||
- Fixed vertical image popup preview scrolling.
|
|
||||||
- Added options to export a subset of collections.
|
|
||||||
- Added option to import a subset of collections without deleting the others ([#3403](https://github.com/pocketbase/pocketbase/issues/3403)).
|
|
||||||
|
|
||||||
- Added support for back/indirect relation `filter`/`sort` (single and multiple).
|
|
||||||
The syntax to reference back relation fields is `yourCollection_via_yourRelField.*`.
|
|
||||||
⚠️ To avoid excessive joins, the nested relations resolver is now limited to max 6 level depth (the same as `expand`).
|
|
||||||
_Note that in the future there will be also more advanced and granular options to specify a subset of the fields that are filterable/sortable._
|
|
||||||
|
|
||||||
- Added support for multiple back/indirect relation `expand` and updated the keys to use the `_via_` reference syntax (`yourCollection_via_yourRelField`).
|
|
||||||
_To minimize the breaking changes, the old parenthesis reference syntax (`yourCollection(yourRelField)`) will still continue to work but it is soft-deprecated and there will be a console log reminding you to change it to the new one._
|
|
||||||
|
|
||||||
- ⚠️ Collections and fields are no longer allowed to have `_via_` in their name to avoid collisions with the back/indirect relation reference syntax.
|
|
||||||
|
|
||||||
- Added `jsvm.Config.OnInit` optional config function to allow registering custom Go bindings to the JSVM.
|
|
||||||
|
|
||||||
- Added `@request.context` rule field that can be used to apply a different set of constraints based on the API rule execution context.
|
|
||||||
For example, to disallow user creation by an OAuth2 auth, you could set for the users Create API rule `@request.context != "oauth2"`.
|
|
||||||
The currently supported `@request.context` values are:
|
|
||||||
```
|
|
||||||
default
|
|
||||||
realtime
|
|
||||||
protectedFile
|
|
||||||
oauth2
|
|
||||||
```
|
|
||||||
|
|
||||||
- Adjusted the `cron.Start()` to start the ticker at the `00` second of the cron interval ([#4394](https://github.com/pocketbase/pocketbase/discussions/4394)).
|
|
||||||
_Note that the cron format has only minute granularity and there is still no guarantee that the scheduled job will be always executed at the `00` second._
|
|
||||||
|
|
||||||
- Fixed auto backups cron not reloading properly after app settings change ([#4431](https://github.com/pocketbase/pocketbase/discussions/4431)).
|
|
||||||
|
|
||||||
- Upgraded to `aws-sdk-go-v2` and added special handling for GCS to workaround the previous [GCS headers signature issue](https://github.com/pocketbase/pocketbase/issues/2231) that we had with v2.
|
|
||||||
_This should also fix the SVG/JSON zero response when using Cloudflare R2 ([#4287](https://github.com/pocketbase/pocketbase/issues/4287#issuecomment-1925168142), [#2068](https://github.com/pocketbase/pocketbase/discussions/2068), [#2952](https://github.com/pocketbase/pocketbase/discussions/2952))._
|
|
||||||
_⚠️ If you are using S3 for uploaded files or backups, please verify that you have a green check in the Admin UI for your S3 configuration (I've tested the new version with GCS, MinIO, Cloudflare R2 and Wasabi)._
|
|
||||||
|
|
||||||
- Added `:each` modifier support for `file` and `relation` type fields (_previously it was supported only for `select` type fields_).
|
|
||||||
|
|
||||||
- Other minor improvements (updated the `ghupdate` plugin to use the configured executable name when printing to the console, fixed the error reporting of `admin update/delete` commands, etc.).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.21.3
|
|
||||||
|
|
||||||
- Ignore the JS required validations for disabled OIDC providers ([#4322](https://github.com/pocketbase/pocketbase/issues/4322)).
|
|
||||||
|
|
||||||
- Allow `HEAD` requests to the `/api/health` endpoint ([#4310](https://github.com/pocketbase/pocketbase/issues/4310)).
|
|
||||||
|
|
||||||
- Fixed the `editor` field value when visualized inside the View collection preview panel.
|
|
||||||
|
|
||||||
- Manually clear all TinyMCE events on editor removal (_workaround for [tinymce#9377](https://github.com/tinymce/tinymce/issues/9377)_).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.21.2
|
|
||||||
|
|
||||||
- Fixed `@request.auth.*` initialization side-effect which caused the current authenticated user email to not being returned in the user auth response ([#2173](https://github.com/pocketbase/pocketbase/issues/2173#issuecomment-1932332038)).
|
|
||||||
_The current authenticated user email should be accessible always no matter of the `emailVisibility` state._
|
|
||||||
|
|
||||||
- Fixed `RecordUpsert.RemoveFiles` godoc example.
|
|
||||||
|
|
||||||
- Bumped to `NumCPU()+2` the `thumbGenSem` limit as some users reported that it was too restrictive.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.21.1
|
|
||||||
|
|
||||||
- Small fix for the Admin UI related to the _Settings > Sync_ menu not being visible even when the "Hide controls" toggle is off.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.21.0
|
|
||||||
|
|
||||||
- Added Bitbucket OAuth2 provider ([#3948](https://github.com/pocketbase/pocketbase/pull/3948); thanks @aabajyan).
|
|
||||||
|
|
||||||
- Mark user as verified on confirm password reset ([#4066](https://github.com/pocketbase/pocketbase/issues/4066)).
|
|
||||||
_If the user email has changed after issuing the reset token (eg. updated by an admin), then the `verified` user state remains unchanged._
|
|
||||||
|
|
||||||
- Added support for loading a serialized json payload for `multipart/form-data` requests using the special `@jsonPayload` key.
|
|
||||||
_This is intended to be used primarily by the SDKs to resolve [js-sdk#274](https://github.com/pocketbase/js-sdk/issues/274)._
|
|
||||||
|
|
||||||
- Added graceful OAuth2 redirect error handling ([#4177](https://github.com/pocketbase/pocketbase/issues/4177)).
|
|
||||||
_Previously on redirect error we were returning directly a standard json error response. Now on redirect error we'll redirect to a generic OAuth2 failure screen (similar to the success one) and will attempt to auto close the OAuth2 popup._
|
|
||||||
_The SDKs are also updated to handle the OAuth2 redirect error and it will be returned as Promise rejection of the `authWithOAuth2()` call._
|
|
||||||
|
|
||||||
- Exposed `$apis.gzip()` and `$apis.bodyLimit(bytes)` middlewares to the JSVM.
|
|
||||||
|
|
||||||
- Added `TestMailer.SentMessages` field that holds all sent test app emails until cleanup.
|
|
||||||
|
|
||||||
- Optimized the cascade delete of records with multiple `relation` fields.
|
|
||||||
|
|
||||||
- Updated the `serve` and `admin` commands error reporting.
|
|
||||||
|
|
||||||
- Minor Admin UI improvements (reduced the min table row height, added option to duplicate fields, added new TinyMCE codesample plugin languages, hide the collection sync settings when the `Settings.Meta.HideControls` is enabled, etc.)
|
|
||||||
|
|
||||||
|
|
||||||
## v0.20.7
|
|
||||||
|
|
||||||
- Fixed the Admin UI auto indexes update when renaming fields with a common prefix ([#4160](https://github.com/pocketbase/pocketbase/issues/4160)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.20.6
|
|
||||||
|
|
||||||
- Fixed JSVM types generation for functions with omitted arg types ([#4145](https://github.com/pocketbase/pocketbase/issues/4145)).
|
|
||||||
|
|
||||||
- Updated Go deps.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.20.5
|
|
||||||
|
|
||||||
- Minor CSS fix for the Admin UI to prevent the searchbar within a popup from expanding too much and pushing the controls out of the visible area ([#4079](https://github.com/pocketbase/pocketbase/issues/4079#issuecomment-1876994116)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.20.4
|
|
||||||
|
|
||||||
- Small fix for a regression introduced with the recent `json` field changes that was causing View collection column expressions recognized as `json` to fail to resolve ([#4072](https://github.com/pocketbase/pocketbase/issues/4072)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.20.3
|
|
||||||
|
|
||||||
- Fixed the `json` field query comparisons to work correctly with plain JSON values like `null`, `bool` `number`, etc. ([#4068](https://github.com/pocketbase/pocketbase/issues/4068)).
|
|
||||||
Since there are plans in the future to allow custom SQLite builds and also in some situations it may be useful to be able to distinguish `NULL` from `''`,
|
|
||||||
for the `json` fields (and for any other future non-standard field) we no longer apply `COALESCE` by default, aka.:
|
|
||||||
```
|
|
||||||
Dataset:
|
|
||||||
1) data: json(null)
|
|
||||||
2) data: json('')
|
|
||||||
|
|
||||||
For the filter "data = null" only 1) will resolve to TRUE.
|
|
||||||
For the filter "data = ''" only 2) will resolve to TRUE.
|
|
||||||
```
|
|
||||||
|
|
||||||
- Minor Go tests improvements
|
|
||||||
- Sorted the record cascade delete references to ensure that the delete operation will preserve the order of the fired events when running the tests.
|
|
||||||
- Marked some of the tests as safe for parallel execution to speed up a little the GitHub action build times.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.20.2
|
|
||||||
|
|
||||||
- Added `sleep(milliseconds)` JSVM binding.
|
|
||||||
_It works the same way as Go `time.Sleep()`, aka. it pauses the goroutine where the JSVM code is running._
|
|
||||||
|
|
||||||
- Fixed multi-line text paste in the Admin UI search bar ([#4022](https://github.com/pocketbase/pocketbase/discussions/4022)).
|
|
||||||
|
|
||||||
- Fixed the monospace font loading in the Admin UI.
|
|
||||||
|
|
||||||
- Fixed various reported docs and code comment typos.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.20.1
|
|
||||||
|
|
||||||
- Added `--dev` flag and its accompanying `app.IsDev()` method (_in place of the previously removed `--debug`_) to assist during development ([#3918](https://github.com/pocketbase/pocketbase/discussions/3918)).
|
|
||||||
The `--dev` flag prints in the console "everything" and more specifically:
|
|
||||||
- the data DB SQL statements
|
|
||||||
- all `app.Logger().*` logs (debug, info, warning, error, etc.), no matter of the logs persistence settings in the Admin UI
|
|
||||||
|
|
||||||
- Minor Admin UI fixes:
|
|
||||||
- Fixed the log `error` label text wrapping.
|
|
||||||
- Added the log `referer` (_when it is from a different source_) and `details` labels in the logs listing.
|
|
||||||
- Removed the blank current time entry from the logs chart because it was causing confusion when used with custom time ranges.
|
|
||||||
- Updated the SQL syntax highlighter and keywords autocompletion in the Admin UI to recognize `CAST(x as bool)` expressions.
|
|
||||||
|
|
||||||
- Replaced the default API tests timeout with a new `ApiScenario.Timeout` option ([#3930](https://github.com/pocketbase/pocketbase/issues/3930)).
|
|
||||||
A negative or zero value means no tests timeout.
|
|
||||||
If a single API test takes more than 3s to complete it will have a log message visible when the test fails or when `go test -v` flag is used.
|
|
||||||
|
|
||||||
- Added timestamp at the beginning of the generated JSVM types file to avoid creating it everytime with the app startup.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.20.0
|
|
||||||
|
|
||||||
- Added `expand`, `filter`, `fields`, custom query and headers parameters support for the realtime subscriptions.
|
|
||||||
_Requires JS SDK v0.20.0+ or Dart SDK v0.17.0+._
|
|
||||||
|
|
||||||
```js
|
|
||||||
// JS SDK v0.20.0
|
|
||||||
pb.collection("example").subscribe("*", (e) => {
|
|
||||||
...
|
|
||||||
}, {
|
|
||||||
expand: "someRelField",
|
|
||||||
filter: "status = 'active'",
|
|
||||||
fields: "id,expand.someRelField.*:excerpt(100)",
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
```dart
|
|
||||||
// Dart SDK v0.17.0
|
|
||||||
pb.collection("example").subscribe("*", (e) {
|
|
||||||
...
|
|
||||||
},
|
|
||||||
expand: "someRelField",
|
|
||||||
filter: "status = 'active'",
|
|
||||||
fields: "id,expand.someRelField.*:excerpt(100)",
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
- Generalized the logs to allow any kind of application logs, not just requests.
|
|
||||||
|
|
||||||
The new `app.Logger()` implements the standard [`log/slog` interfaces](https://pkg.go.dev/log/slog) available with Go 1.21.
|
|
||||||
```
|
|
||||||
// Go: https://pocketbase.io/docs/go-logging/
|
|
||||||
app.Logger().Info("Example message", "total", 123, "details", "lorem ipsum...")
|
|
||||||
|
|
||||||
// JS: https://pocketbase.io/docs/js-logging/
|
|
||||||
$app.logger().info("Example message", "total", 123, "details", "lorem ipsum...")
|
|
||||||
```
|
|
||||||
|
|
||||||
For better performance and to minimize blocking on hot paths, logs are currently written with
|
|
||||||
debounce and on batches:
|
|
||||||
- 3 seconds after the last debounced log write
|
|
||||||
- when the batch threshold is reached (currently 200)
|
|
||||||
- right before app termination to attempt saving everything from the existing logs queue
|
|
||||||
|
|
||||||
Some notable log related changes:
|
|
||||||
|
|
||||||
- ⚠️ Bumped the minimum required Go version to 1.21.
|
|
||||||
|
|
||||||
- ⚠️ Removed `_requests` table in favor of the generalized `_logs`.
|
|
||||||
_Note that existing logs will be deleted!_
|
|
||||||
|
|
||||||
- ⚠️ Renamed the following `Dao` log methods:
|
|
||||||
```go
|
|
||||||
Dao.RequestQuery(...) -> Dao.LogQuery(...)
|
|
||||||
Dao.FindRequestById(...) -> Dao.FindLogById(...)
|
|
||||||
Dao.RequestsStats(...) -> Dao.LogsStats(...)
|
|
||||||
Dao.DeleteOldRequests(...) -> Dao.DeleteOldLogs(...)
|
|
||||||
Dao.SaveRequest(...) -> Dao.SaveLog(...)
|
|
||||||
```
|
|
||||||
- ⚠️ Removed `app.IsDebug()` and the `--debug` flag.
|
|
||||||
This was done to avoid the confusion with the new logger and its debug severity level.
|
|
||||||
If you want to store debug logs you can set `-4` as min log level from the Admin UI.
|
|
||||||
|
|
||||||
- Refactored Admin UI Logs:
|
|
||||||
- Added new logs table listing.
|
|
||||||
- Added log settings option to toggle the IP logging for the activity logger.
|
|
||||||
- Added log settings option to specify a minimum log level.
|
|
||||||
- Added controls to export individual or bulk selected logs as json.
|
|
||||||
- Other minor improvements and fixes.
|
|
||||||
|
|
||||||
- Added new `filesystem/System.Copy(src, dest)` method to copy existing files from one location to another.
|
|
||||||
_This is usually useful when duplicating records with `file` field(s) programmatically._
|
|
||||||
|
|
||||||
- Added `filesystem.NewFileFromUrl(ctx, url)` helper method to construct a `*filesystem.BytesReader` file from the specified url.
|
|
||||||
|
|
||||||
- OAuth2 related additions:
|
|
||||||
|
|
||||||
- Added new `PKCE()` and `SetPKCE(enable)` OAuth2 methods to indicate whether the PKCE flow is supported or not.
|
|
||||||
_The PKCE value is currently configurable from the UI only for the OIDC providers._
|
|
||||||
_This was added to accommodate OIDC providers that may throw an error if unsupported PKCE params are submitted with the auth request (eg. LinkedIn; see [#3799](https://github.com/pocketbase/pocketbase/discussions/3799#discussioncomment-7640312))._
|
|
||||||
|
|
||||||
- Added new `displayName` field for each `listAuthMethods()` OAuth2 provider item.
|
|
||||||
_The value of the `displayName` property is currently configurable from the UI only for the OIDC providers._
|
|
||||||
|
|
||||||
- Added `expiry` field to the OAuth2 user response containing the _optional_ expiration time of the OAuth2 access token ([#3617](https://github.com/pocketbase/pocketbase/discussions/3617)).
|
|
||||||
|
|
||||||
- Allow a single OAuth2 user to be used for authentication in multiple auth collection.
|
|
||||||
_⚠️ Because now you can have more than one external provider with `collectionId-provider-providerId` pair, `Dao.FindExternalAuthByProvider(provider, providerId)` method was removed in favour of the more generic `Dao.FindFirstExternalAuthByExpr(expr)`._
|
|
||||||
|
|
||||||
- Added `onlyVerified` auth collection option to globally disallow authentication requests for unverified users.
|
|
||||||
|
|
||||||
- Added support for single line comments (ex. `// your comment`) in the API rules and filter expressions.
|
|
||||||
|
|
||||||
- Added support for specifying a collection alias in `@collection.someCollection:alias.*`.
|
|
||||||
|
|
||||||
- Soft-deprecated and renamed `app.Cache()` with `app.Store()`.
|
|
||||||
|
|
||||||
- Minor JSVM updates and fixes:
|
|
||||||
|
|
||||||
- Updated `$security.parseUnverifiedJWT(token)` and `$security.parseJWT(token, key)` to return the token payload result as plain object.
|
|
||||||
|
|
||||||
- Added `$apis.requireGuestOnly()` middleware JSVM binding ([#3896](https://github.com/pocketbase/pocketbase/issues/3896)).
|
|
||||||
|
|
||||||
- Use `IS NOT` instead of `!=` as not-equal SQL query operator to handle the cases when comparing with nullable columns or expressions (eg. `json_extract` over `json` field).
|
|
||||||
_Based on my local dataset I wasn't able to find a significant difference in the performance between the 2 operators, but if you stumble on a query that you think may be affected negatively by this, please report it and I'll test it further._
|
|
||||||
|
|
||||||
- Added `MaxSize` `json` field option to prevent storing large json data in the db ([#3790](https://github.com/pocketbase/pocketbase/issues/3790)).
|
|
||||||
_Existing `json` fields are updated with a system migration to have a ~2MB size limit (it can be adjusted from the Admin UI)._
|
|
||||||
|
|
||||||
- Fixed negative string number normalization support for the `json` field type.
|
|
||||||
|
|
||||||
- Trigger the `app.OnTerminate()` hook on `app.Restart()` call.
|
|
||||||
_A new bool `IsRestart` field was also added to the `core.TerminateEvent` event._
|
|
||||||
|
|
||||||
- Fixed graceful shutdown handling and speed up a little the app termination time.
|
|
||||||
|
|
||||||
- Limit the concurrent thumbs generation to avoid high CPU and memory usage in spiky scenarios ([#3794](https://github.com/pocketbase/pocketbase/pull/3794); thanks @t-muehlberger).
|
|
||||||
_Currently the max concurrent thumbs generation processes are limited to "total of logical process CPUs + 1"._
|
|
||||||
_This is arbitrary chosen and may change in the future depending on the users feedback and usage patterns._
|
|
||||||
_If you are experiencing OOM errors during large image thumb generations, especially in container environment, you can try defining the `GOMEMLIMIT=500MiB` env variable before starting the executable._
|
|
||||||
|
|
||||||
- Slightly speed up (~10%) the thumbs generation by changing from cubic (`CatmullRom`) to bilinear (`Linear`) resampling filter (_the quality difference is very little_).
|
|
||||||
|
|
||||||
- Added a default red colored Stderr output in case of a console command error.
|
|
||||||
_You can now also silence individually custom commands errors using the `cobra.Command.SilenceErrors` field._
|
|
||||||
|
|
||||||
- Fixed links formatting in the autogenerated html->text mail body.
|
|
||||||
|
|
||||||
- Removed incorrectly imported empty `local('')` font-face declarations.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.19.4
|
|
||||||
|
|
||||||
- Fixed TinyMCE source code viewer textarea styles ([#3715](https://github.com/pocketbase/pocketbase/issues/3715)).
|
|
||||||
|
|
||||||
- Fixed `text` field min/max validators to properly count multi-byte characters ([#3735](https://github.com/pocketbase/pocketbase/issues/3735)).
|
|
||||||
|
|
||||||
- Allowed hyphens in `username` ([#3697](https://github.com/pocketbase/pocketbase/issues/3697)).
|
|
||||||
_More control over the system fields settings will be available in the future._
|
|
||||||
|
|
||||||
- Updated the JSVM generated types to use directly the value type instead of `* | undefined` union in functions/methods return declarations.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.19.3
|
|
||||||
|
|
||||||
- Added the release notes to the console output of `./pocketbase update` ([#3685](https://github.com/pocketbase/pocketbase/discussions/3685)).
|
|
||||||
|
|
||||||
- Added missing documentation for the JSVM `$mails.*` bindings.
|
|
||||||
|
|
||||||
- Relaxed the OAuth2 redirect url validation to allow any string value ([#3689](https://github.com/pocketbase/pocketbase/pull/3689); thanks @sergeypdev).
|
|
||||||
_Note that the redirect url format is still bound to the accepted values by the specific OAuth2 provider._
|
|
||||||
|
|
||||||
|
|
||||||
## v0.19.2
|
|
||||||
|
|
||||||
- Updated the JSVM generated types ([#3627](https://github.com/pocketbase/pocketbase/issues/3627), [#3662](https://github.com/pocketbase/pocketbase/issues/3662)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.19.1
|
|
||||||
|
|
||||||
- Fixed `tokenizer.Scan()/ScanAll()` to ignore the separators from the default trim cutset.
|
|
||||||
An option to return also the empty found tokens was also added via `Tokenizer.KeepEmptyTokens(true)`.
|
|
||||||
_This should fix the parsing of whitespace characters around view query column names when no quotes are used ([#3616](https://github.com/pocketbase/pocketbase/discussions/3616#discussioncomment-7398564))._
|
|
||||||
|
|
||||||
- Fixed the `:excerpt(max, withEllipsis?)` `fields` query param modifier to properly add space to the generated text fragment after block tags.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.19.0
|
|
||||||
|
|
||||||
- Added Patreon OAuth2 provider ([#3323](https://github.com/pocketbase/pocketbase/pull/3323); thanks @ghostdevv).
|
|
||||||
|
|
||||||
- Added mailcow OAuth2 provider ([#3364](https://github.com/pocketbase/pocketbase/pull/3364); thanks @thisni1s).
|
|
||||||
|
|
||||||
- Added support for `:excerpt(max, withEllipsis?)` `fields` modifier that will return a short plain text version of any string value (html tags are stripped).
|
|
||||||
This could be used to minimize the downloaded json data when listing records with large `editor` html values.
|
|
||||||
```js
|
|
||||||
await pb.collection("example").getList(1, 20, {
|
|
||||||
"fields": "*,description:excerpt(100)"
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
- Several Admin UI improvements:
|
|
||||||
- Count the total records separately to speed up the query execution for large datasets ([#3344](https://github.com/pocketbase/pocketbase/issues/3344)).
|
|
||||||
- Enclosed the listing scrolling area within the table so that the horizontal scrollbar and table header are always reachable ([#2505](https://github.com/pocketbase/pocketbase/issues/2505)).
|
|
||||||
- Allowed opening the record preview/update form via direct URL ([#2682](https://github.com/pocketbase/pocketbase/discussions/2682)).
|
|
||||||
- Reintroduced the local `date` field tooltip on hover.
|
|
||||||
- Speed up the listing loading times for records with large `editor` field values by initially fetching only a partial of the records data (the complete record data is loaded on record preview/update).
|
|
||||||
- Added "Media library" (collection images picker) support for the TinyMCE `editor` field.
|
|
||||||
- Added support to "pin" collections in the sidebar.
|
|
||||||
- Added support to manually resize the collections sidebar.
|
|
||||||
- More clear "Nonempty" field label style.
|
|
||||||
- Removed the legacy `.woff` and `.ttf` fonts and keep only `.woff2`.
|
|
||||||
|
|
||||||
- Removed the explicit `Content-Type` charset from the realtime response due to compatibility issues with IIS ([#3461](https://github.com/pocketbase/pocketbase/issues/3461)).
|
|
||||||
_The `Connection:keep-alive` realtime response header was also removed as it is not really used with HTTP2 anyway._
|
|
||||||
|
|
||||||
- Added new JSVM bindings:
|
|
||||||
- `new Cookie({ ... })` constructor for creating `*http.Cookie` equivalent value.
|
|
||||||
- `new SubscriptionMessage({ ... })` constructor for creating a custom realtime subscription payload.
|
|
||||||
- Soft-deprecated `$os.exec()` in favour of `$os.cmd()` to make it more clear that the call only prepares the command and doesn't execute it.
|
|
||||||
|
|
||||||
- ⚠️ Bumped the min required Go version to 1.19.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.10
|
|
||||||
|
|
||||||
- Added global `raw` template function to allow outputting raw/verbatim HTML content in the JSVM templates ([#3476](https://github.com/pocketbase/pocketbase/discussions/3476)).
|
|
||||||
```
|
|
||||||
{{.description|raw}}
|
|
||||||
```
|
|
||||||
|
|
||||||
- Trimmed view query semicolon and allowed single quotes for column aliases ([#3450](https://github.com/pocketbase/pocketbase/issues/3450#issuecomment-1748044641)).
|
|
||||||
_Single quotes are usually [not a valid identifier quote characters](https://www.sqlite.org/lang_keywords.html), but for resilience and compatibility reasons SQLite allows them in some contexts where only an identifier is expected._
|
|
||||||
|
|
||||||
- Bumped the GitHub action to use [min Go 1.21.2](https://github.com/golang/go/issues?q=milestone%3AGo1.21.2) (_the fixed issues are not critical as they are mostly related to the compiler/build tools_).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.9
|
|
||||||
|
|
||||||
- Fixed empty thumbs directories not getting deleted on Windows after deleting a record img file ([#3382](https://github.com/pocketbase/pocketbase/issues/3382)).
|
|
||||||
|
|
||||||
- Updated the generated JSVM typings to silent the TS warnings when trying to access a field/method in a Go->TS interface.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.8
|
|
||||||
|
|
||||||
- Minor fix for the View collections API Preview and Admin UI listings incorrectly showing the `created` and `updated` fields as `N/A` when the view query doesn't have them.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.7
|
|
||||||
|
|
||||||
- Fixed JS error in the Admin UI when listing records with invalid `relation` field value ([#3372](https://github.com/pocketbase/pocketbase/issues/3372)).
|
|
||||||
_This could happen usually only during custom SQL import scripts or when directly modifying the record field value without data validations._
|
|
||||||
|
|
||||||
- Updated Go deps and the generated JSVM types.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.6
|
|
||||||
|
|
||||||
- Return the response headers and cookies in the `$http.send()` result ([#3310](https://github.com/pocketbase/pocketbase/discussions/3310)).
|
|
||||||
|
|
||||||
- Added more descriptive internal error message for missing user/admin email on password reset requests.
|
|
||||||
|
|
||||||
- Updated Go deps.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.5
|
|
||||||
|
|
||||||
- Fixed minor Admin UI JS error in the auth collection options panel introduced with the change from v0.18.4.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.4
|
|
||||||
|
|
||||||
- Added escape character (`\`) support in the Admin UI to allow using `select` field values with comma ([#2197](https://github.com/pocketbase/pocketbase/discussions/2197)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.3
|
|
||||||
|
|
||||||
- Exposed a global JSVM `readerToString(reader)` helper function to allow reading Go `io.Reader` values ([#3273](https://github.com/pocketbase/pocketbase/discussions/3273)).
|
|
||||||
|
|
||||||
- Bumped the GitHub action to use [min Go 1.21.1](https://github.com/golang/go/issues?q=milestone%3AGo1.21.1+label%3ACherryPickApproved) for the prebuilt executable since it contains some minor `html/template` and `net/http` security fixes.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.2
|
|
||||||
|
|
||||||
- Prevent breaking the record form in the Admin UI in case the browser's localStorage quota has been exceeded when uploading or storing large `editor` values ([#3265](https://github.com/pocketbase/pocketbase/issues/3265)).
|
|
||||||
|
|
||||||
- Updated docs and missing JSVM typings.
|
|
||||||
|
|
||||||
- Exposed additional crypto primitives under the `$security.*` JSVM namespace ([#3273](https://github.com/pocketbase/pocketbase/discussions/3273)):
|
|
||||||
```js
|
|
||||||
// HMAC with SHA256
|
|
||||||
$security.hs256("hello", "secret")
|
|
||||||
|
|
||||||
// HMAC with SHA512
|
|
||||||
$security.hs512("hello", "secret")
|
|
||||||
|
|
||||||
// compare 2 strings with a constant time
|
|
||||||
$security.equal(hash1, hash2)
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.1
|
|
||||||
|
|
||||||
- Excluded the local temp dir from the backups ([#3261](https://github.com/pocketbase/pocketbase/issues/3261)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.18.0
|
|
||||||
|
|
||||||
- Simplified the `serve` command to accept domain name(s) as argument to reduce any additional manual hosts setup that sometimes previously was needed when deploying on production ([#3190](https://github.com/pocketbase/pocketbase/discussions/3190)).
|
|
||||||
```sh
|
|
||||||
./pocketbase serve yourdomain.com
|
|
||||||
```
|
|
||||||
|
|
||||||
- Added `fields` wildcard (`*`) support.
|
|
||||||
|
|
||||||
- Added option to upload a backup file from the Admin UI ([#2599](https://github.com/pocketbase/pocketbase/issues/2599)).
|
|
||||||
|
|
||||||
- Registered a custom Deflate compressor to speedup (_nearly 2-3x_) the backups generation for the sake of a small zip size increase.
|
|
||||||
_Based on several local tests, `pb_data` of ~500MB (from which ~350MB+ are several hundred small files) results in a ~280MB zip generated for ~11s (previously it resulted in ~250MB zip but for ~35s)._
|
|
||||||
|
|
||||||
- Added the application name as part of the autogenerated backup name for easier identification ([#3066](https://github.com/pocketbase/pocketbase/issues/3066)).
|
|
||||||
|
|
||||||
- Added new `SmtpConfig.LocalName` option to specify a custom domain name (or IP address) for the initial EHLO/HELO exchange ([#3097](https://github.com/pocketbase/pocketbase/discussions/3097)).
|
|
||||||
_This is usually required for verification purposes only by some SMTP providers, such as on-premise [Gmail SMTP-relay](https://support.google.com/a/answer/2956491)._
|
|
||||||
|
|
||||||
- Added `NoDecimal` `number` field option.
|
|
||||||
|
|
||||||
- `editor` field improvements:
|
|
||||||
- Added new "Strip urls domain" option to allow controlling the default TinyMCE urls behavior (_default to `false` for new content_).
|
|
||||||
- Normalized pasted text while still preserving links, lists, tables, etc. formatting ([#3257](https://github.com/pocketbase/pocketbase/issues/3257)).
|
|
||||||
|
|
||||||
- Added option to auto generate admin and auth record passwords from the Admin UI.
|
|
||||||
|
|
||||||
- Added JSON validation and syntax highlight for the `json` field in the Admin UI ([#3191](https://github.com/pocketbase/pocketbase/issues/3191)).
|
|
||||||
|
|
||||||
- Added datetime filter macros:
|
|
||||||
```
|
|
||||||
// all macros are UTC based
|
|
||||||
@second - @now second number (0-59)
|
|
||||||
@minute - @now minute number (0-59)
|
|
||||||
@hour - @now hour number (0-23)
|
|
||||||
@weekday - @now weekday number (0-6)
|
|
||||||
@day - @now day number
|
|
||||||
@month - @now month number
|
|
||||||
@year - @now year number
|
|
||||||
@todayStart - beginning of the current day as datetime string
|
|
||||||
@todayEnd - end of the current day as datetime string
|
|
||||||
@monthStart - beginning of the current month as datetime string
|
|
||||||
@monthEnd - end of the current month as datetime string
|
|
||||||
@yearStart - beginning of the current year as datetime string
|
|
||||||
@yearEnd - end of the current year as datetime string
|
|
||||||
```
|
|
||||||
|
|
||||||
- Added cron expression macros ([#3132](https://github.com/pocketbase/pocketbase/issues/3132)):
|
|
||||||
```
|
|
||||||
@yearly - "0 0 1 1 *"
|
|
||||||
@annually - "0 0 1 1 *"
|
|
||||||
@monthly - "0 0 1 * *"
|
|
||||||
@weekly - "0 0 * * 0"
|
|
||||||
@daily - "0 0 * * *"
|
|
||||||
@midnight - "0 0 * * *"
|
|
||||||
@hourly - "0 * * * *"
|
|
||||||
```
|
|
||||||
|
|
||||||
- ⚠️ Added offset argument `Dao.FindRecordsByFilter(collection, filter, sort, limit, offset, [params...])`.
|
|
||||||
_If you don't need an offset, you can set it to `0`._
|
|
||||||
|
|
||||||
- To minimize the footguns with `Dao.FindFirstRecordByFilter()` and `Dao.FindRecordsByFilter()`, the functions now supports an optional placeholder params argument that is safe to be populated with untrusted user input.
|
|
||||||
The placeholders are in the same format as when binding regular SQL parameters.
|
|
||||||
```go
|
|
||||||
// unsanitized and untrusted filter variables
|
|
||||||
status := "..."
|
|
||||||
author := "..."
|
|
||||||
|
|
||||||
app.Dao().FindFirstRecordByFilter("articles", "status={:status} && author={:author}", dbx.Params{
|
|
||||||
"status": status,
|
|
||||||
"author": author,
|
|
||||||
})
|
|
||||||
|
|
||||||
app.Dao().FindRecordsByFilter("articles", "status={:status} && author={:author}", "-created", 10, 0, dbx.Params{
|
|
||||||
"status": status,
|
|
||||||
"author": author,
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
- Added JSVM `$mails.*` binds for the corresponding Go [mails package](https://pkg.go.dev/github.com/pocketbase/pocketbase/mails) functions.
|
|
||||||
|
|
||||||
- Added JSVM helper crypto primitives under the `$security.*` namespace:
|
|
||||||
```js
|
|
||||||
$security.md5(text)
|
|
||||||
$security.sha256(text)
|
|
||||||
$security.sha512(text)
|
|
||||||
```
|
|
||||||
|
|
||||||
- ⚠️ Deprecated `RelationOptions.DisplayFields` in favor of the new `SchemaField.Presentable` option to avoid the duplication when a single collection is referenced more than once and/or by multiple other collections.
|
|
||||||
|
|
||||||
- ⚠️ Fill the `LastVerificationSentAt` and `LastResetSentAt` fields only after a successfull email send ([#3121](https://github.com/pocketbase/pocketbase/issues/3121)).
|
|
||||||
|
|
||||||
- ⚠️ Skip API `fields` json transformations for non 20x responses ([#3176](https://github.com/pocketbase/pocketbase/issues/3176)).
|
|
||||||
|
|
||||||
- ⚠️ Changes to `tests.ApiScenario` struct:
|
|
||||||
|
|
||||||
- The `ApiScenario.AfterTestFunc` now receive as 3rd argument `*http.Response` pointer instead of `*echo.Echo` as the latter is not really useful in this context.
|
|
||||||
```go
|
|
||||||
// old
|
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo)
|
|
||||||
|
|
||||||
// new
|
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response)
|
|
||||||
```
|
|
||||||
|
|
||||||
- The `ApiScenario.TestAppFactory` now accept the test instance as argument and no longer expect an error as return result ([#3025](https://github.com/pocketbase/pocketbase/discussions/3025#discussioncomment-6592272)).
|
|
||||||
```go
|
|
||||||
// old
|
|
||||||
TestAppFactory: func() (*tests.TestApp, error)
|
|
||||||
|
|
||||||
// new
|
|
||||||
TestAppFactory: func(t *testing.T) *tests.TestApp
|
|
||||||
```
|
|
||||||
_Returning a `nil` app instance from the factory results in test failure. You can enforce a custom test failure by calling `t.Fatal(err)` inside the factory._
|
|
||||||
|
|
||||||
- Bumped the min required TLS version to 1.2 in order to improve the cert reputation score.
|
|
||||||
|
|
||||||
- Reduced the default JSVM prewarmed pool size to 25 to reduce the initial memory consumptions (_you can manually adjust the pool size with `--hooksPool=50` if you need to, but the default should suffice for most cases_).
|
|
||||||
|
|
||||||
- Update `gocloud.dev` dependency to v0.34 and explicitly set the new `NoTempDir` fileblob option to prevent the cross-device link error introduced with v0.33.
|
|
||||||
|
|
||||||
- Other minor Admin UI and docs improvements.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.17.7
|
|
||||||
|
|
||||||
- Fixed the autogenerated `down` migrations to properly revert the old collection rules in case a change was made in `up` ([#3192](https://github.com/pocketbase/pocketbase/pull/3192); thanks @impact-merlinmarek).
|
|
||||||
_Existing `down` migrations can't be fixed but that should be ok as usually the `down` migrations are rarely used against prod environments since they can cause data loss and, while not ideal, the previous old behavior of always setting the rules to `null/nil` is safer than not updating the rules at all._
|
|
||||||
|
|
||||||
- Updated some Go deps.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.17.6
|
|
||||||
|
|
||||||
- Fixed JSVM `require()` file path error when using Windows-style path delimiters ([#3163](https://github.com/pocketbase/pocketbase/issues/3163#issuecomment-1685034438)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.17.5
|
|
||||||
|
|
||||||
- Added quotes around the wrapped view query columns introduced with v0.17.4.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.17.4
|
|
||||||
|
|
||||||
- Fixed Views record retrieval when numeric id is used ([#3110](https://github.com/pocketbase/pocketbase/issues/3110)).
|
|
||||||
_With this fix we also now properly recognize `CAST(... as TEXT)` and `CAST(... as BOOLEAN)` as `text` and `bool` fields._
|
|
||||||
|
|
||||||
- Fixed `relation` "Cascade delete" tooltip message ([#3098](https://github.com/pocketbase/pocketbase/issues/3098)).
|
|
||||||
|
|
||||||
- Fixed jsvm error message prefix on failed migrations ([#3103](https://github.com/pocketbase/pocketbase/pull/3103); thanks @nzhenev).
|
|
||||||
|
|
||||||
- Disabled the initial Admin UI admins counter cache when there are no initial admins to allow detecting externally created accounts (eg. with the `admin` command) ([#3106](https://github.com/pocketbase/pocketbase/issues/3106)).
|
|
||||||
|
|
||||||
- Downgraded `google/go-cloud` dependency to v0.32.0 until v0.34.0 is released to prevent the `os.TempDir` `cross-device link` errors as too many users complained about it.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.17.3
|
|
||||||
|
|
||||||
- Fixed Docker `cross-device link` error when creating `pb_data` backups on a local mounted volume ([#3089](https://github.com/pocketbase/pocketbase/issues/3089)).
|
|
||||||
|
|
||||||
- Fixed the error messages for relation to views ([#3090](https://github.com/pocketbase/pocketbase/issues/3090)).
|
|
||||||
|
|
||||||
- Always reserve space for the scrollbar to reduce the layout shifts in the Admin UI records listing due to the deprecated `overflow: overlay`.
|
|
||||||
|
|
||||||
- Enabled lazy loading for the Admin UI thumb images.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.17.2
|
|
||||||
|
|
||||||
- Soft-deprecated `$http.send({ data: object, ... })` in favour of `$http.send({ body: rawString, ... })`
|
|
||||||
to allow sending non-JSON body with the request ([#3058](https://github.com/pocketbase/pocketbase/discussions/3058)).
|
|
||||||
The existing `data` prop will still work, but it is recommended to use `body` instead (_to send JSON you can use `JSON.stringify(...)` as body value_).
|
|
||||||
|
|
||||||
- Added `core.RealtimeConnectEvent.IdleTimeout` field to allow specifying a different realtime idle timeout duration per client basis ([#3054](https://github.com/pocketbase/pocketbase/discussions/3054)).
|
|
||||||
|
|
||||||
- Fixed `apis.RequestData` deprecation log note ([#3068](https://github.com/pocketbase/pocketbase/pull/3068); thanks @gungjodi).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.17.1
|
|
||||||
|
|
||||||
- Use relative path when redirecting to the OAuth2 providers page in the Admin UI to support subpath deployments ([#3026](https://github.com/pocketbase/pocketbase/pull/3026); thanks @sonyarianto).
|
|
||||||
|
|
||||||
- Manually trigger the `OnBeforeServe` hook for `tests.ApiScenario` ([#3025](https://github.com/pocketbase/pocketbase/discussions/3025)).
|
|
||||||
|
|
||||||
- Trigger the JSVM `cronAdd()` handler only on app `serve` to prevent unexpected (and eventually duplicated) cron handler calls when custom console commands are used ([#3024](https://github.com/pocketbase/pocketbase/discussions/3024#discussioncomment-6592703)).
|
|
||||||
|
|
||||||
- The `console.log()` messages are now written to the `stdout` instead of `stderr`.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.17.0
|
|
||||||
|
|
||||||
- New more detailed guides for using PocketBase as framework (both Go and JS).
|
|
||||||
_If you find any typos or issues with the docs please report them in https://github.com/pocketbase/site._
|
|
||||||
|
|
||||||
- Added new experimental JavaScript app hooks binding via [goja](https://github.com/dop251/goja).
|
|
||||||
They are available by default with the prebuilt executable if you create `*.pb.js` file(s) in the `pb_hooks` directory.
|
|
||||||
Lower your expectations because the integration comes with some limitations. For more details please check the [Extend with JavaScript](https://pocketbase.io/docs/js-overview/) guide.
|
|
||||||
Optionally, you can also enable the JS app hooks as part of a custom Go build for dynamic scripting but you need to register the `jsvm` plugin manually:
|
|
||||||
```go
|
|
||||||
jsvm.MustRegister(app core.App, config jsvm.Config{})
|
|
||||||
```
|
|
||||||
|
|
||||||
- Added Instagram OAuth2 provider ([#2534](https://github.com/pocketbase/pocketbase/pull/2534); thanks @pnmcosta).
|
|
||||||
|
|
||||||
- Added VK OAuth2 provider ([#2533](https://github.com/pocketbase/pocketbase/pull/2533); thanks @imperatrona).
|
|
||||||
|
|
||||||
- Added Yandex OAuth2 provider ([#2762](https://github.com/pocketbase/pocketbase/pull/2762); thanks @imperatrona).
|
|
||||||
|
|
||||||
- Added new fields to `core.ServeEvent`:
|
|
||||||
```go
|
|
||||||
type ServeEvent struct {
|
|
||||||
App App
|
|
||||||
Router *echo.Echo
|
|
||||||
// new fields
|
|
||||||
Server *http.Server // allows adjusting the HTTP server config (global timeouts, TLS options, etc.)
|
|
||||||
CertManager *autocert.Manager // allows adjusting the autocert options (cache dir, host policy, etc.)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
- Added `record.ExpandedOne(rel)` and `record.ExpandedAll(rel)` helpers to retrieve casted single or multiple expand relations from the already loaded "expand" Record data.
|
|
||||||
|
|
||||||
- Added rule and filter record `Dao` helpers:
|
|
||||||
```go
|
|
||||||
app.Dao().FindRecordsByFilter("posts", "title ~ 'lorem ipsum' && visible = true", "-created", 10)
|
|
||||||
app.Dao().FindFirstRecordByFilter("posts", "slug='test' && active=true")
|
|
||||||
app.Dao().CanAccessRecord(record, requestInfo, rule)
|
|
||||||
```
|
|
||||||
|
|
||||||
- Added `Dao.WithoutHooks()` helper to create a new `Dao` from the current one but without the create/update/delete hooks.
|
|
||||||
|
|
||||||
- Use a default fetch function that will return all relations in case the `fetchFunc` argument of `Dao.ExpandRecord(record, expands, fetchFunc)` and `Dao.ExpandRecords(records, expands, fetchFunc)` is `nil`.
|
|
||||||
|
|
||||||
- For convenience it is now possible to call `Dao.RecordQuery(collectionModelOrIdentifier)` with just the collection id or name.
|
|
||||||
In case an invalid collection id/name string is passed the query will be resolved with cancelled context error.
|
|
||||||
|
|
||||||
- Refactored `apis.ApiError` validation errors serialization to allow `map[string]error` and `map[string]any` when generating the public safe formatted `ApiError.Data`.
|
|
||||||
|
|
||||||
- Added support for wrapped API errors (_in case Go 1.20+ is used with multiple wrapped errors, the first `apis.ApiError` takes precedence_).
|
|
||||||
|
|
||||||
- Added `?download=1` file query parameter to the file serving endpoint to force the browser to always download the file and not show its preview.
|
|
||||||
|
|
||||||
- Added new utility `github.com/pocketbase/pocketbase/tools/template` subpackage to assist with rendering HTML templates using the standard Go `html/template` and `text/template` syntax.
|
|
||||||
|
|
||||||
- Added `types.JsonMap.Get(k)` and `types.JsonMap.Set(k, v)` helpers for the cases where the type aliased direct map access is not allowed (eg. in [goja](https://pkg.go.dev/github.com/dop251/goja#hdr-Maps_with_methods)).
|
|
||||||
|
|
||||||
- Soft-deprecated `security.NewToken()` in favor of `security.NewJWT()`.
|
|
||||||
|
|
||||||
- `Hook.Add()` and `Hook.PreAdd` now returns a unique string identifier that could be used to remove the registered hook handler via `Hook.Remove(handlerId)`.
|
|
||||||
|
|
||||||
- Changed the after* hooks to be called right before writing the user response, allowing users to return response errors from the after hooks.
|
|
||||||
There is also no longer need for returning explicitly `hook.StopPropagtion` when writing custom response body in a hook because we will skip the finalizer response body write if a response was already "committed".
|
|
||||||
|
|
||||||
- ⚠️ Renamed `*Options{}` to `Config{}` for consistency and replaced the unnecessary pointers with their value equivalent to keep the applied configuration defaults isolated within their function calls:
|
|
||||||
```go
|
|
||||||
old: pocketbase.NewWithConfig(config *pocketbase.Config) *pocketbase.PocketBase
|
|
||||||
new: pocketbase.NewWithConfig(config pocketbase.Config) *pocketbase.PocketBase
|
|
||||||
|
|
||||||
old: core.NewBaseApp(config *core.BaseAppConfig) *core.BaseApp
|
|
||||||
new: core.NewBaseApp(config core.BaseAppConfig) *core.BaseApp
|
|
||||||
|
|
||||||
old: apis.Serve(app core.App, options *apis.ServeOptions) error
|
|
||||||
new: apis.Serve(app core.App, config apis.ServeConfig) (*http.Server, error)
|
|
||||||
|
|
||||||
old: jsvm.MustRegisterMigrations(app core.App, options *jsvm.MigrationsOptions)
|
|
||||||
new: jsvm.MustRegister(app core.App, config jsvm.Config)
|
|
||||||
|
|
||||||
old: ghupdate.MustRegister(app core.App, rootCmd *cobra.Command, options *ghupdate.Options)
|
|
||||||
new: ghupdate.MustRegister(app core.App, rootCmd *cobra.Command, config ghupdate.Config)
|
|
||||||
|
|
||||||
old: migratecmd.MustRegister(app core.App, rootCmd *cobra.Command, options *migratecmd.Options)
|
|
||||||
new: migratecmd.MustRegister(app core.App, rootCmd *cobra.Command, config migratecmd.Config)
|
|
||||||
```
|
|
||||||
|
|
||||||
- ⚠️ Changed the type of `subscriptions.Message.Data` from `string` to `[]byte` because `Data` usually is a json bytes slice anyway.
|
|
||||||
|
|
||||||
- ⚠️ Renamed `models.RequestData` to `models.RequestInfo` and soft-deprecated `apis.RequestData(c)` in favor of `apis.RequestInfo(c)` to avoid the stuttering with the `Data` field.
|
|
||||||
_The old `apis.RequestData()` method still works to minimize the breaking changes but it is recommended to replace it with `apis.RequestInfo(c)`._
|
|
||||||
|
|
||||||
- ⚠️ Changes to the List/Search APIs
|
|
||||||
- Added new query parameter `?skipTotal=1` to skip the `COUNT` query performed with the list/search actions ([#2965](https://github.com/pocketbase/pocketbase/discussions/2965)).
|
|
||||||
If `?skipTotal=1` is set, the response fields `totalItems` and `totalPages` will have `-1` value (this is to avoid having different JSON responses and to differentiate from the zero default).
|
|
||||||
With the latest JS SDK 0.16+ and Dart SDK v0.11+ versions `skipTotal=1` is set by default for the `getFirstListItem()` and `getFullList()` requests.
|
|
||||||
|
|
||||||
- The count and regular select statements also now executes concurrently, meaning that we no longer perform normalization over the `page` parameter and in case the user
|
|
||||||
request a page that doesn't exist (eg. `?page=99999999`) we'll return empty `items` array.
|
|
||||||
|
|
||||||
- Reverted the default `COUNT` column to `id` as there are some common situations where it can negatively impact the query performance.
|
|
||||||
Additionally, from this version we also set `PRAGMA temp_store = MEMORY` so that also helps with the temp B-TREE creation when `id` is used.
|
|
||||||
_There are still scenarios where `COUNT` queries with `rowid` executes faster, but the majority of the time when nested relations lookups are used it seems to have the opposite effect (at least based on the benchmarks dataset)._
|
|
||||||
|
|
||||||
- ⚠️ Disallowed relations to views **from non-view** collections ([#3000](https://github.com/pocketbase/pocketbase/issues/3000)).
|
|
||||||
The change was necessary because I wasn't able to find an efficient way to track view changes and the previous behavior could have too many unexpected side-effects (eg. view with computed ids).
|
|
||||||
There is a system migration that will convert the existing view `relation` fields to `json` (multiple) and `text` (single) fields.
|
|
||||||
This could be a breaking change if you have `relation` to view and use `expand` or some of the `relation` view fields as part of a collection rule.
|
|
||||||
|
|
||||||
- ⚠️ Added an extra `action` argument to the `Dao` hooks to allow skipping the default persist behavior.
|
|
||||||
In preparation for the logs generalization, the `Dao.After*Func` methods now also allow returning an error.
|
|
||||||
|
|
||||||
- Allowed `0` as `RelationOptions.MinSelect` value to avoid the ambiguity between 0 and non-filled input value ([#2817](https://github.com/pocketbase/pocketbase/discussions/2817)).
|
|
||||||
|
|
||||||
- Fixed zero-default value not being used if the field is not explicitly set when manually creating records ([#2992](https://github.com/pocketbase/pocketbase/issues/2992)).
|
|
||||||
Additionally, `record.Get(field)` will now always return normalized value (the same as in the json serialization) for consistency and to avoid ambiguities with what is stored in the related DB table.
|
|
||||||
The schema fields columns `DEFAULT` definition was also updated for new collections to ensure that `NULL` values can't be accidentally inserted.
|
|
||||||
|
|
||||||
- Fixed `migrate down` not returning the correct `lastAppliedMigrations()` when the stored migration applied time is in seconds.
|
|
||||||
|
|
||||||
- Fixed realtime delete event to be called after the record was deleted from the DB (_including transactions and cascade delete operations_).
|
|
||||||
|
|
||||||
- Other minor fixes and improvements (typos and grammar fixes, updated dependencies, removed unnecessary 404 error check in the Admin UI, etc.).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.10
|
|
||||||
|
|
||||||
- Added multiple valued fields (`relation`, `select`, `file`) normalizations to ensure that the zero-default value of a newly created multiple field is applied for already existing data ([#2930](https://github.com/pocketbase/pocketbase/issues/2930)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.9
|
|
||||||
|
|
||||||
- Register the `eagerRequestInfoCache` middleware only for the internal `api` group routes to avoid conflicts with custom route handlers ([#2914](https://github.com/pocketbase/pocketbase/issues/2914)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.8
|
|
||||||
|
|
||||||
- Fixed unique validator detailed error message not being returned when camelCase field name is used ([#2868](https://github.com/pocketbase/pocketbase/issues/2868)).
|
|
||||||
|
|
||||||
- Updated the index parser to allow no space between the table name and the columns list ([#2864](https://github.com/pocketbase/pocketbase/discussions/2864#discussioncomment-6373736)).
|
|
||||||
|
|
||||||
- Updated go deps.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.7
|
|
||||||
|
|
||||||
- Minor optimization for the list/search queries to use `rowid` with the `COUNT` statement when available.
|
|
||||||
_This eliminates the temp B-TREE step when executing the query and for large datasets (eg. 150k) it could have 10x improvement (from ~580ms to ~60ms)._
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.6
|
|
||||||
|
|
||||||
- Fixed collection index column sort normalization in the Admin UI ([#2681](https://github.com/pocketbase/pocketbase/pull/2681); thanks @SimonLoir).
|
|
||||||
|
|
||||||
- Removed unnecessary admins count in `apis.RequireAdminAuthOnlyIfAny()` middleware ([#2726](https://github.com/pocketbase/pocketbase/pull/2726); thanks @svekko).
|
|
||||||
|
|
||||||
- Fixed `multipart/form-data` request bind not populating map array values ([#2763](https://github.com/pocketbase/pocketbase/discussions/2763#discussioncomment-6278902)).
|
|
||||||
|
|
||||||
- Upgraded npm and Go dependencies.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.5
|
|
||||||
|
|
||||||
- Fixed the Admin UI serialization of implicit relation display fields ([#2675](https://github.com/pocketbase/pocketbase/issues/2675)).
|
|
||||||
|
|
||||||
- Reset the Admin UI sort in case the active sort collection field is renamed or deleted.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.4
|
|
||||||
|
|
||||||
- Fixed the selfupdate command not working on Windows due to missing `.exe` in the extracted binary path ([#2589](https://github.com/pocketbase/pocketbase/discussions/2589)).
|
|
||||||
_Note that the command on Windows will work from v0.16.4+ onwards, meaning that you still will have to update manually one more time to v0.16.4._
|
|
||||||
|
|
||||||
- Added `int64`, `int32`, `uint`, `uint64` and `uint32` support when scanning `types.DateTime` ([#2602](https://github.com/pocketbase/pocketbase/discussions/2602))
|
|
||||||
|
|
||||||
- Updated dependencies.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.3
|
|
||||||
|
|
||||||
- Fixed schema fields sort not working on Safari/Gnome Web ([#2567](https://github.com/pocketbase/pocketbase/issues/2567)).
|
|
||||||
|
|
||||||
- Fixed default `PRAGMA`s not being applied for new connections ([#2570](https://github.com/pocketbase/pocketbase/discussions/2570)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.2
|
|
||||||
|
|
||||||
- Fixed backups archive not excluding the local `backups` directory on Windows ([#2548](https://github.com/pocketbase/pocketbase/discussions/2548#discussioncomment-5979712)).
|
|
||||||
|
|
||||||
- Changed file field to not use `dataTransfer.effectAllowed` when dropping files since it is not reliable and consistent across different OS and browsers ([#2541](https://github.com/pocketbase/pocketbase/issues/2541)).
|
|
||||||
|
|
||||||
- Auto register the initial generated snapshot migration to prevent incorrectly reapplying the snapshot on Docker restart ([#2551](https://github.com/pocketbase/pocketbase/discussions/2551)).
|
|
||||||
|
|
||||||
- Fixed missing view id field error message typo.
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.1
|
|
||||||
|
|
||||||
- Fixed backup restore not working in a container environment when `pb_data` is mounted as volume ([#2519](https://github.com/pocketbase/pocketbase/issues/2519)).
|
|
||||||
|
|
||||||
- Fixed Dart SDK realtime API preview example ([#2523](https://github.com/pocketbase/pocketbase/pull/2523); thanks @xFrann).
|
|
||||||
|
|
||||||
- Fixed typo in the backups create panel ([#2526](https://github.com/pocketbase/pocketbase/pull/2526); thanks @dschissler).
|
|
||||||
|
|
||||||
- Removed unnecessary slice length check in `list.ExistInSlice` ([#2527](https://github.com/pocketbase/pocketbase/pull/2527); thanks @KunalSin9h).
|
|
||||||
|
|
||||||
- Avoid mutating the cached request data on OAuth2 user create ([#2535](https://github.com/pocketbase/pocketbase/discussions/2535)).
|
|
||||||
|
|
||||||
- Fixed Export Collections "Download as JSON" ([#2540](https://github.com/pocketbase/pocketbase/issues/2540)).
|
|
||||||
|
|
||||||
- Fixed file field drag and drop not working in Firefox and Safari ([#2541](https://github.com/pocketbase/pocketbase/issues/2541)).
|
|
||||||
|
|
||||||
|
|
||||||
## v0.16.0
|
|
||||||
|
|
||||||
- Added automated backups (_+ cron rotation_) APIs and UI for the `pb_data` directory.
|
|
||||||
The backups can be also initialized programmatically using `app.CreateBackup("backup.zip")`.
|
|
||||||
There is also experimental restore method - `app.RestoreBackup("backup.zip")` (_currently works only on UNIX systems as it relies on execve_).
|
|
||||||
The backups can be stored locally or in external S3 storage (_it has its own configuration, separate from the file uploads storage filesystem_).
|
|
||||||
|
|
||||||
- Added option to limit the returned API fields using the `?fields` query parameter.
|
|
||||||
The "fields picker" is applied for `SearchResult.Items` and every other JSON response. For example:
|
|
||||||
```js
|
|
||||||
// original: {"id": "RECORD_ID", "name": "abc", "description": "...something very big...", "items": ["id1", "id2"], "expand": {"items": [{"id": "id1", "name": "test1"}, {"id": "id2", "name": "test2"}]}}
|
|
||||||
// output: {"name": "abc", "expand": {"items": [{"name": "test1"}, {"name": "test2"}]}}
|
|
||||||
const result = await pb.collection("example").getOne("RECORD_ID", {
|
|
||||||
expand: "items",
|
|
||||||
fields: "name,expand.items.name",
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
- Added new `./pocketbase update` command to selfupdate the prebuilt executable (with option to generate a backup of your `pb_data`).
|
|
||||||
|
|
||||||
- Added new `./pocketbase admin` console command:
|
|
||||||
```sh
|
|
||||||
// creates new admin account
|
|
||||||
./pocketbase admin create test@example.com 123456890
|
|
||||||
|
|
||||||
// changes the password of an existing admin account
|
|
||||||
./pocketbase admin update test@example.com 0987654321
|
|
||||||
|
|
||||||
// deletes single admin account (if exists)
|
|
||||||
./pocketbase admin delete test@example.com
|
|
||||||
```
|
|
||||||
|
|
||||||
- Added `apis.Serve(app, options)` helper to allow starting the API server programmatically.
|
|
||||||
|
|
||||||
- Updated the schema fields Admin UI for "tidier" fields visualization.
|
|
||||||
|
|
||||||
- Updated the logs "real" user IP to check for `Fly-Client-IP` header and changed the `X-Forward-For` header to use the first non-empty leftmost-ish IP as it the closest to the "real IP".
|
|
||||||
|
|
||||||
- Added new `tools/archive` helper subpackage for managing archives (_currently works only with zip_).
|
|
||||||
|
|
||||||
- Added new `tools/cron` helper subpackage for scheduling task using cron-like syntax (_this eventually may get exported in the future in a separate repo_).
|
|
||||||
|
|
||||||
- Added new `Filesystem.List(prefix)` helper to retrieve a flat list with all files under the provided prefix.
|
|
||||||
|
|
||||||
- Added new `App.NewBackupsFilesystem()` helper to create a dedicated filesystem abstraction for managing app data backups.
|
|
||||||
|
|
||||||
- Added new `App.OnTerminate()` hook (_executed right before app termination, eg. on `SIGTERM` signal_).
|
|
||||||
|
|
||||||
- Added `accept` file field attribute with the field MIME types ([#2466](https://github.com/pocketbase/pocketbase/pull/2466); thanks @Nikhil1920).
|
|
||||||
|
|
||||||
- Added support for multiple files sort in the Admin UI ([#2445](https://github.com/pocketbase/pocketbase/issues/2445)).
|
|
||||||
|
|
||||||
- Added support for multiple relations sort in the Admin UI.
|
|
||||||
|
|
||||||
- Added `meta.isNew` to the OAuth2 auth JSON response to indicate a newly OAuth2 created PocketBase user.
|
|
@ -1,17 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
Copyright (c) 2022 - present, Gani Georgiev
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
||||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
||||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
||||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
||||||
is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
||||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
||||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -43,7 +43,7 @@ routerAdd(
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
$app.dao().db().newQuery("SELECT DISTINCT DATE(created) as created FROM insights").all(result)
|
$app.dao().db().newQuery("SELECT DISTINCT DATE(created, 'localtime') as created FROM insights").all(result)
|
||||||
|
|
||||||
return c.json(
|
return c.json(
|
||||||
200,
|
200,
|
||||||
|
2
client/web/.env.development
Normal file
2
client/web/.env.development
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
VITE_API_BASE=http://localhost:7777
|
||||||
|
VITE_PB_BASE=http://localhost:8090
|
2
client/web/.env.production
Normal file
2
client/web/.env.production
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
VITE_API_BASE=http://localhost:7777
|
||||||
|
VITE_PB_BASE=http://localhost:8090
|
13
client/web/.eslintrc.cjs
Normal file
13
client/web/.eslintrc.cjs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
env: { browser: true, es2020: true },
|
||||||
|
extends: ['eslint:recommended', 'plugin:react/recommended', 'plugin:react/jsx-runtime', 'plugin:react-hooks/recommended'],
|
||||||
|
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||||
|
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
|
||||||
|
settings: { react: { version: '18.2' } },
|
||||||
|
plugins: ['react-refresh'],
|
||||||
|
rules: {
|
||||||
|
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
|
||||||
|
'react/prop-types': 'off',
|
||||||
|
},
|
||||||
|
}
|
24
client/web/.gitignore
vendored
Normal file
24
client/web/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
6
client/web/README.md
Normal file
6
client/web/README.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
web env:
|
||||||
|
VITE_API_BASE=http://localhost:7777
|
||||||
|
VITE_PB_BASE=http://localhost:8090
|
||||||
|
|
||||||
|
pocketase env:
|
||||||
|
AW_FILE_DIR=xxx
|
17
client/web/components.json
Normal file
17
client/web/components.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://ui.shadcn.com/schema.json",
|
||||||
|
"style": "default",
|
||||||
|
"rsc": false,
|
||||||
|
"tsx": false,
|
||||||
|
"tailwind": {
|
||||||
|
"config": "tailwind.config.js",
|
||||||
|
"css": "src/index.css",
|
||||||
|
"baseColor": "slate",
|
||||||
|
"cssVariables": true,
|
||||||
|
"prefix": ""
|
||||||
|
},
|
||||||
|
"aliases": {
|
||||||
|
"components": "@/components",
|
||||||
|
"utils": "@/lib/utils"
|
||||||
|
}
|
||||||
|
}
|
13
client/web/index.html
Normal file
13
client/web/index.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>情报分析</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.jsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
56
client/web/package.json
Normal file
56
client/web/package.json
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
{
|
||||||
|
"name": "asweb-react",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build",
|
||||||
|
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@hookform/resolvers": "^3.3.4",
|
||||||
|
"@radix-ui/react-accordion": "^1.1.2",
|
||||||
|
"@radix-ui/react-label": "^2.0.2",
|
||||||
|
"@radix-ui/react-slot": "^1.0.2",
|
||||||
|
"@radix-ui/react-toast": "^1.1.5",
|
||||||
|
"@rollup/rollup-linux-x64-gnu": "^4.9.6",
|
||||||
|
"@tanstack/react-query": "^5.17.9",
|
||||||
|
"@tanstack/react-query-devtools": "^5.17.9",
|
||||||
|
"axios": "^1.6.8",
|
||||||
|
"class-variance-authority": "^0.7.0",
|
||||||
|
"clsx": "^2.1.0",
|
||||||
|
"lucide-react": "^0.309.0",
|
||||||
|
"nanoid": "^5.0.4",
|
||||||
|
"pocketbase": "^0.21.0",
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-dom": "^18.2.0",
|
||||||
|
"react-hook-form": "^7.49.3",
|
||||||
|
"redaxios": "^0.5.1",
|
||||||
|
"tailwind-merge": "^2.2.0",
|
||||||
|
"tailwindcss-animate": "^1.0.7",
|
||||||
|
"wouter": "^3.1.0",
|
||||||
|
"zod": "^3.22.4",
|
||||||
|
"zustand": "^4.4.7"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^20.11.0",
|
||||||
|
"@types/react": "^18.2.43",
|
||||||
|
"@types/react-dom": "^18.2.17",
|
||||||
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
|
"autoprefixer": "^10.4.16",
|
||||||
|
"eslint": "^8.55.0",
|
||||||
|
"eslint-plugin-react": "^7.33.2",
|
||||||
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
|
"eslint-plugin-react-refresh": "^0.4.5",
|
||||||
|
"postcss": "^8.4.33",
|
||||||
|
"tailwindcss": "^3.4.1",
|
||||||
|
"vite": "^5.0.8"
|
||||||
|
},
|
||||||
|
"pnpm": {
|
||||||
|
"overrides": {
|
||||||
|
"rollup": "npm:@rollup/wasm-node"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3374
client/web/pnpm-lock.yaml
generated
Normal file
3374
client/web/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
6
client/web/postcss.config.js
Normal file
6
client/web/postcss.config.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export default {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {},
|
||||||
|
},
|
||||||
|
}
|
1
client/web/public/vite.svg
Normal file
1
client/web/public/vite.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
13
client/web/src/App.css
Normal file
13
client/web/src/App.css
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#root {
|
||||||
|
max-width: 1280px;
|
||||||
|
min-height: 100%;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 2rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
54
client/web/src/App.jsx
Normal file
54
client/web/src/App.jsx
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { QueryClient, QueryClientProvider, QueryCache, useQueryClient } from "@tanstack/react-query"
|
||||||
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
|
||||||
|
|
||||||
|
import "./App.css"
|
||||||
|
|
||||||
|
import { Toaster } from "@/components/ui/toaster"
|
||||||
|
import { useToast } from "@/components/ui/use-toast"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import LoginScreen from "@/components/screen/login"
|
||||||
|
// import Steps from "@/components/screen/steps"
|
||||||
|
import InsightsScreen from "@/components/screen/insights"
|
||||||
|
import ArticlesScreen from "@/components/screen/articles"
|
||||||
|
import ReportScreen from "@/components/screen/report"
|
||||||
|
|
||||||
|
import { isAuth } from "@/store"
|
||||||
|
|
||||||
|
const queryClient = new QueryClient()
|
||||||
|
|
||||||
|
import { Route, Switch, useLocation } from "wouter"
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
const [, setLocation] = useLocation()
|
||||||
|
if (!isAuth()) {
|
||||||
|
setLocation("/login")
|
||||||
|
}
|
||||||
|
// const { toast } = useToast()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<Switch>
|
||||||
|
<Route path='/' component={InsightsScreen} />
|
||||||
|
<Route path='/login' component={LoginScreen} />
|
||||||
|
<Route path='/insights' component={InsightsScreen} />
|
||||||
|
<Route path='/articles' component={ArticlesScreen} />
|
||||||
|
<Route path='/report/:insight_id' component={ReportScreen} />
|
||||||
|
<Route>404</Route>
|
||||||
|
</Switch>
|
||||||
|
{/* <Button
|
||||||
|
onClick={() => {
|
||||||
|
toast({
|
||||||
|
title: "Scheduled: Catch up",
|
||||||
|
description: "Friday, February 10, 2023 at 5:57 PM",
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Show Toast
|
||||||
|
</Button> */}
|
||||||
|
<Toaster />
|
||||||
|
<ReactQueryDevtools initialIsOpen={false} />
|
||||||
|
</QueryClientProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App
|
1
client/web/src/assets/react.svg
Normal file
1
client/web/src/assets/react.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
After Width: | Height: | Size: 4.0 KiB |
33
client/web/src/components/article-list.jsx
Normal file
33
client/web/src/components/article-list.jsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Delete } from "lucide-react"
|
||||||
|
|
||||||
|
// data expecting object {"0":{}, "1":{}}
|
||||||
|
export function ArticleList({ data, showActions, onDelete }) {
|
||||||
|
return (
|
||||||
|
<div className='grid w-full gap-1.5'>
|
||||||
|
<div className='border overflow-hidden'>
|
||||||
|
{data &&
|
||||||
|
data.map((article, i) => (
|
||||||
|
<div key={i} className='border-b px-4 py-2 flex gap-2'>
|
||||||
|
<div className='flex-1 whitespace-nowrap min-w-0'>
|
||||||
|
<p className='font-normal w-full truncate underline text-left'>
|
||||||
|
<a href={article.url} target='_blank' rel='noreferrer'>
|
||||||
|
{article.expand?.translation_result?.title || article.title}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p className='font-light min-w-0 truncate text-left'>{article.expand?.translation_result?.abstract || article.abstract}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{showActions && (
|
||||||
|
<Button variant='ghost' className='text-red-500' onClick={() => onDelete(article.id)}>
|
||||||
|
<Delete className='h-4 w-4' />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{data && <p className='text-sm text-muted-foreground mt-4'>共{Object.keys(data).length}篇文章</p>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
21
client/web/src/components/layout/step.jsx
Normal file
21
client/web/src/components/layout/step.jsx
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
||||||
|
export default function StepLayout({ title, description, children, navigate }) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='mx-auto text-left'>
|
||||||
|
<div className='flex gap-4'>
|
||||||
|
<div className='flex-1'>
|
||||||
|
<h1 className='mt-10 scroll-m-20 pb-2 text-3xl font-semibold tracking-tight transition-colors first:mt-0'>{title}</h1>
|
||||||
|
{description && <p className='text-xl text-muted-foreground'>{description}</p>}
|
||||||
|
</div>
|
||||||
|
{/* <Button variant='outline' onClick={() => navigate("/start")}>
|
||||||
|
新建任务
|
||||||
|
</Button> */}
|
||||||
|
</div>
|
||||||
|
<hr className='my-4'></hr>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
74
client/web/src/components/screen/articles.jsx
Normal file
74
client/web/src/components/screen/articles.jsx
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import { useEffect } from "react"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { ArticleList } from "../article-list"
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
||||||
|
import { Languages } from "lucide-react"
|
||||||
|
import { ButtonLoading } from "@/components/ui/button-loading"
|
||||||
|
import { useDatePager, useArticleDates, useArticles, translations } from "@/store"
|
||||||
|
|
||||||
|
import { useLocation } from "wouter"
|
||||||
|
|
||||||
|
function ArticlesScreen({}) {
|
||||||
|
const [, navigate] = useLocation()
|
||||||
|
|
||||||
|
const queryDates = useArticleDates()
|
||||||
|
const { index, last, next, hasLast, hasNext } = useDatePager(queryDates.data)
|
||||||
|
const currentDate = queryDates.data && index >= 0 ? queryDates.data[index] : ""
|
||||||
|
const query = useArticles(currentDate)
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
const mut = useMutation({
|
||||||
|
mutationFn: (data) => {
|
||||||
|
return translations(data)
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["articles", currentDate] })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function trans() {
|
||||||
|
mut.mutate({ article_ids: query.data.map((d) => d.id) })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h2>文章</h2>
|
||||||
|
{query.isError && <p className='text-red-500 my-4'>{query.error.message}</p>}
|
||||||
|
<div className='my-6 flex gap-4 w-fit'>
|
||||||
|
<Button onClick={() => navigate("/insights")}>查看分析结果</Button>
|
||||||
|
{mut.isPending && <ButtonLoading />}
|
||||||
|
{!mut.isPending && query.data && query.data.length > 0 && query.data.filter((a) => !a.translation_result).length > 0 && (
|
||||||
|
<Button variant='outline' className='text-blue-400 mb-6' onClick={trans}>
|
||||||
|
<Languages className='w-4 h-4' />
|
||||||
|
一键翻译
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{currentDate && (
|
||||||
|
<div className='my-6 flex gap-4 flex items-center'>
|
||||||
|
<Button disabled={!hasLast()} variant='outline' onClick={last}>
|
||||||
|
<
|
||||||
|
</Button>
|
||||||
|
<p>{currentDate}</p>
|
||||||
|
<Button disabled={!hasNext()} variant='outline' onClick={next}>
|
||||||
|
>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{/* {completed && !Object.values(query.data.articles)[0]["zh-cn"] && (
|
||||||
|
<Button variant='link' className='text-blue-400 mb-6' onClick={trans}>
|
||||||
|
<Languages className='w-4 h-4' />
|
||||||
|
一键翻译
|
||||||
|
</Button>
|
||||||
|
)} */}
|
||||||
|
|
||||||
|
{query.data && <ArticleList data={query.data} />}
|
||||||
|
|
||||||
|
<div className='my-6 flex gap-4'>
|
||||||
|
<Button onClick={() => navigate("/insights")}>查看分析结果</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ArticlesScreen
|
160
client/web/src/components/screen/insights.jsx
Normal file
160
client/web/src/components/screen/insights.jsx
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
import { useEffect } from "react"
|
||||||
|
import { useLocation } from "wouter"
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
||||||
|
import { Files } from "lucide-react"
|
||||||
|
import { ArticleList } from "@/components/article-list"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Toaster } from "@/components/ui/toaster"
|
||||||
|
import { ButtonLoading } from "@/components/ui/button-loading"
|
||||||
|
import { useToast } from "@/components/ui/use-toast"
|
||||||
|
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
|
||||||
|
import { useClientStore, useInsights, unlinkArticle, useInsightDates, useDatePager, more } from "@/store"
|
||||||
|
|
||||||
|
function List({ insights, selected, onOpen, onDelete, onReport, onMore, isGettingMore, error }) {
|
||||||
|
function change(value) {
|
||||||
|
if (value) onOpen(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function unlink(article_id) {
|
||||||
|
onDelete(selected, article_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Accordion type='single' collapsible onValueChange={change} className='w-full'>
|
||||||
|
{insights.map((insight, i) => (
|
||||||
|
<AccordionItem value={insight.id} key={i}>
|
||||||
|
<AccordionTrigger className='hover:no-underline'>
|
||||||
|
<div className='px-4 py-2 cursor-pointer flex items-center gap-2 overflow-hidden'>
|
||||||
|
{selected === insight.id && <div className='-ml-4 w-2 h-2 bg-green-400 rounded-full'></div>}
|
||||||
|
<p className={"truncate text-wrap text-left flex-1 " + (selected === insight.id ? "font-bold" : "font-normal")}>{insight.content}</p>
|
||||||
|
<div className='flex items-center justify-center gap-1'>
|
||||||
|
<Files className='h-4 w-4 text-slate-400' />
|
||||||
|
<span className='text-slate-400 text-sm leading-none'>x {insight.expand.articles.length}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</AccordionTrigger>
|
||||||
|
<AccordionContent className='px-4'>
|
||||||
|
<ArticleList data={insight.expand.articles} showActions={true} onDelete={unlink} />
|
||||||
|
{error && <p className='text-red-500 my-4'>{error.message}</p>}
|
||||||
|
|
||||||
|
{(isGettingMore && <ButtonLoading />) || (
|
||||||
|
<div className='flex gap-4 justify-center'>
|
||||||
|
<Button onClick={onReport} className='my-4'>
|
||||||
|
生成报告
|
||||||
|
</Button>
|
||||||
|
<Button variant='outline' onClick={onMore} className='my-4'>
|
||||||
|
搜索更多
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</AccordionContent>
|
||||||
|
</AccordionItem>
|
||||||
|
))}
|
||||||
|
</Accordion>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function InsightsScreen({}) {
|
||||||
|
const selectedInsight = useClientStore((state) => state.selectedInsight)
|
||||||
|
const selectInsight = useClientStore((state) => state.selectInsight)
|
||||||
|
const dates = useInsightDates()
|
||||||
|
const { index, last, next, hasLast, hasNext } = useDatePager(dates)
|
||||||
|
// console.log(dates, index)
|
||||||
|
const currentDate = dates.length > 0 && index >= 0 ? dates[index] : ""
|
||||||
|
const data = useInsights(currentDate)
|
||||||
|
// console.log(data)
|
||||||
|
const [, navigate] = useLocation()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const mut = useMutation({
|
||||||
|
mutationFn: (data) => {
|
||||||
|
if (data && selectInsight && data.find((insight) => insight.id == selectedInsight).expand.articles.length == 1) {
|
||||||
|
throw new Error("不能删除最后一篇文章")
|
||||||
|
}
|
||||||
|
return unlinkArticle(data)
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["insights", currentDate] })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const mutMore = useMutation({
|
||||||
|
mutationFn: (data) => {
|
||||||
|
return more(data)
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["insights", currentDate] })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const { toast } = useToast()
|
||||||
|
const queryCache = queryClient.getQueryCache()
|
||||||
|
queryCache.onError = (error) => {
|
||||||
|
console.log("error in cache", error)
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "出错啦!",
|
||||||
|
description: error.message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
selectInsight(null)
|
||||||
|
}, [index])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
mut.reset() // only show error with the selected insight
|
||||||
|
}, [selectedInsight])
|
||||||
|
|
||||||
|
function unlink(insight_id, article_id) {
|
||||||
|
mut.mutate({ insight_id, article_id })
|
||||||
|
}
|
||||||
|
|
||||||
|
function report() {
|
||||||
|
navigate("/report/" + selectedInsight)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMore() {
|
||||||
|
console.log()
|
||||||
|
mutMore.mutate({ insight_id: selectedInsight })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h2>分析结果</h2>
|
||||||
|
{currentDate && (
|
||||||
|
<div className='my-6 flex gap-4 flex items-center'>
|
||||||
|
<Button disabled={!hasLast()} variant='outline' onClick={last}>
|
||||||
|
<
|
||||||
|
</Button>
|
||||||
|
<p>{currentDate}</p>
|
||||||
|
<Button disabled={!hasNext()} variant='outline' onClick={next}>
|
||||||
|
>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{data && (
|
||||||
|
<div className='grid w-full gap-1.5'>
|
||||||
|
<div className='flex gap-2 items-center'>
|
||||||
|
<div className='flex-1'>{<p className=''>选择一项结果生成文档</p>}</div>
|
||||||
|
</div>
|
||||||
|
<div className='w-full gap-1.5'>
|
||||||
|
<div className=''>
|
||||||
|
<List insights={data} selected={selectedInsight} onOpen={(id) => selectInsight(id)} onDelete={unlink} onReport={report} onMore={getMore} isGettingMore={mutMore.isPending} error={mut.error} />
|
||||||
|
</div>
|
||||||
|
<p className='text-sm text-muted-foreground mt-4'>共{Object.keys(data).length}条结果</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className='my-6 flex flex-col gap-4 w-36 text-left'>
|
||||||
|
<Button variant='outline' onClick={() => navigate("/articles")}>
|
||||||
|
查看所有文章
|
||||||
|
</Button>
|
||||||
|
<a href={`${import.meta.env.VITE_PB_BASE}/_/`} target='__blank' className='text-sm underline'>
|
||||||
|
数据库管理 >
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default InsightsScreen
|
82
client/web/src/components/screen/login.jsx
Normal file
82
client/web/src/components/screen/login.jsx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
// import { zodResolver } from '@hookform/resolvers/zod'
|
||||||
|
import { useForm } from 'react-hook-form'
|
||||||
|
// import * as z from 'zod'
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
|
||||||
|
import { Input } from '@/components/ui/input'
|
||||||
|
|
||||||
|
import { useLocation } from 'wouter'
|
||||||
|
import { login } from '@/store'
|
||||||
|
|
||||||
|
// const FormSchema = z.object({
|
||||||
|
// username: z.string().nonempty('请填写用户名'),
|
||||||
|
// password: z.string().nonempty('请填写密码'),
|
||||||
|
// })
|
||||||
|
|
||||||
|
export function AdminLoginScreen() {
|
||||||
|
const form = useForm({
|
||||||
|
// resolver: zodResolver(FormSchema),
|
||||||
|
defaultValues: {
|
||||||
|
username: '',
|
||||||
|
password: '',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const [, setLocation] = useLocation()
|
||||||
|
const mutation = useMutation({
|
||||||
|
mutationFn: login,
|
||||||
|
onSuccess: (data) => {
|
||||||
|
setLocation('/')
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function onSubmit(e) {
|
||||||
|
mutation.mutate({ username: form.getValues('username'), password: form.getValues('password') })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="max-w-sm mx-auto text-left">
|
||||||
|
<h2 className="mt-10 scroll-m-20 pb-2 text-3xl font-semibold tracking-tight transition-colors first:mt-0">登录</h2>
|
||||||
|
<p className="text-xl text-muted-foreground">输入账号及密码</p>
|
||||||
|
<hr className="my-6"></hr>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="mx-auto space-y-6">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="username"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="text-left">
|
||||||
|
<FormLabel>用户名</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription></FormDescription>
|
||||||
|
<FormMessage>{mutation?.error?.response?.data?.['identity']?.message}</FormMessage>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="password"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="text-left">
|
||||||
|
<FormLabel>密码</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="" {...field} type="password" />
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription></FormDescription>
|
||||||
|
<FormMessage>{mutation?.error?.response?.data?.['password']?.message}</FormMessage>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<p className="text-sm text-destructive">{mutation?.error?.message}</p>
|
||||||
|
<Button type="submit">登录</Button>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdminLoginScreen
|
98
client/web/src/components/screen/report.jsx
Normal file
98
client/web/src/components/screen/report.jsx
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { ButtonLoading } from "@/components/ui/button-loading"
|
||||||
|
import { FileDown } from "lucide-react"
|
||||||
|
import { useClientStore, report, useInsight } from "@/store"
|
||||||
|
import { useEffect } from "react"
|
||||||
|
import { useLocation, useParams } from "wouter"
|
||||||
|
|
||||||
|
function ReportScreen({}) {
|
||||||
|
// const selectedInsight = useClientStore((state) => state.selectedInsight)
|
||||||
|
// const workflow_name = useClientStore((state) => state.workflow_name)
|
||||||
|
// const taskId = useClientStore((state) => state.taskId)
|
||||||
|
// const [wasWorking, setWasWorking] = useState(false)
|
||||||
|
|
||||||
|
const toc = useClientStore((state) => state.toc)
|
||||||
|
const updateToc = useClientStore((state) => state.updateToc)
|
||||||
|
const comment = useClientStore((state) => state.comment)
|
||||||
|
const updateComment = useClientStore((state) => state.updateComment)
|
||||||
|
|
||||||
|
const [, navigate] = useLocation()
|
||||||
|
const params = useParams()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!params || !params.insight_id) {
|
||||||
|
console.log("expect /report/[insight_id]")
|
||||||
|
navigate("/insights", { replace: true })
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const query = useInsight(params.insight_id)
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
const mut = useMutation({
|
||||||
|
mutationFn: async (data) => report(data),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["insight", params.insight_id] })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function changeToc(e) {
|
||||||
|
let lines = e.target.value.split("\n")
|
||||||
|
if (lines.length == 1 && lines[0] == "") lines = []
|
||||||
|
// updateToc(lines.filter((l) => l.trim()))
|
||||||
|
updateToc(lines)
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeComment(e) {
|
||||||
|
updateComment(e.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function submit(e) {
|
||||||
|
mut.mutate({ toc: toc, insight_id: params.insight_id, comment: comment })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div>
|
||||||
|
<h3 className='my-4'>已选择分析结果:</h3>
|
||||||
|
{query.data && <div className='bg-slate-100 px-4 py-2 mb-4 text-slate-600 max-w-96 mx-auto'>{query.data.content}</div>}
|
||||||
|
</div>
|
||||||
|
<div className='grid gap-1.5'>
|
||||||
|
<h3 className='my-4'>报告大纲:</h3>
|
||||||
|
<Textarea placeholder='' id='outline' rows='10' value={toc.join("\n")} onChange={changeToc} className='max-w-96 mx-auto' />
|
||||||
|
<small>首行输入标题,每个纲目或章节单独一行. 首行空白自动生成标题. </small>
|
||||||
|
{query.data?.docx && <Input placeholder='修改意见' className='mt-6 max-w-96 mx-auto' value={comment} onChange={changeComment} />}
|
||||||
|
</div>
|
||||||
|
<div className='my-6 flex flex-col gap-4 w-max mx-auto'>
|
||||||
|
{(mut.isPending && <ButtonLoading />) || (
|
||||||
|
<Button disabled={toc.length <= 0} onClick={submit}>
|
||||||
|
{query.data?.docx ? "再次生成" : "生成"}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{!mut.isPending && (
|
||||||
|
<Button variant='outline' onClick={() => navigate("/insights")}>
|
||||||
|
选择其他分析结果
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{!mut.isPending && query.data?.docx && (
|
||||||
|
<div className='grid gap-1.5 max-w-96 border rounded px-4 py-2 pb-6 mx-auto'>
|
||||||
|
<p className='my-4'>报告已生成,点击下载</p>
|
||||||
|
<p className='bg-slate-100 px-4 py-2 hover:underline flex gap-2 items-center overflow-hidden'>
|
||||||
|
<FileDown className='h-4 w-4 text-slate-400' />
|
||||||
|
<a className='truncate ' href={`${import.meta.env.VITE_PB_BASE}/api/files/${query.data.collectionName}/${query.data.id}/${query.data.docx}`} target='_blank' rel='noreferrer'>
|
||||||
|
{query.data.docx}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{query.isError && <p className='text-red-500 my-4'>{query.error.message}</p>}
|
||||||
|
{mut.isError && <p className='text-red-500 my-4'>{mut.error.message}</p>}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ReportScreen
|
58
client/web/src/components/screen/start.jsx
Normal file
58
client/web/src/components/screen/start.jsx
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { ButtonLoading } from "@/components/ui/button-loading"
|
||||||
|
import { useMutation } from "@tanstack/react-query"
|
||||||
|
import { Minus, Plus, Loader2 } from "lucide-react"
|
||||||
|
import { useClientStore, createTask } from "@/store"
|
||||||
|
|
||||||
|
function StartScreen({ navigate, id }) {
|
||||||
|
const s = useClientStore()
|
||||||
|
const mut = useMutation({
|
||||||
|
mutationFn: (data) => createTask(data),
|
||||||
|
onSuccess: () => {
|
||||||
|
//query.invalidate()
|
||||||
|
navigate("/articles")
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function change(e) {
|
||||||
|
let urls = e.target.value.split("\n")
|
||||||
|
if (urls.length == 1 && urls[0] == "") urls = []
|
||||||
|
s.setUrls(urls)
|
||||||
|
}
|
||||||
|
|
||||||
|
function submit() {
|
||||||
|
mut.mutate({ urls: s.urls, days: s.days })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='grid w-full gap-1.5'>
|
||||||
|
<Label htmlFor='message'>网站清单</Label>
|
||||||
|
<Textarea placeholder='每行输入一个网站的主域名,以http://或https://开头' id='message' rows='20' value={s.urls.join("\n")} onChange={change} />
|
||||||
|
{s.countUrls() > 0 && <p className='text-sm text-muted-foreground'>共{s.countUrls()}个网站</p>}
|
||||||
|
<div className='my-6 select-none'>
|
||||||
|
仅抓取
|
||||||
|
<Button variant='outline' size='icon' disabled={s.minDays()} className='mx-2' onClick={s.decr}>
|
||||||
|
<Minus className='h-4 w-4' />
|
||||||
|
</Button>
|
||||||
|
<span className='font-mono'>{s.days}</span>
|
||||||
|
<Button variant='outline' size='icon' disabled={s.maxDays()} className='mx-2' onClick={s.incr}>
|
||||||
|
<Plus className='h-4 w-4' />
|
||||||
|
</Button>
|
||||||
|
天内更新的文章
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{mut.isError && <p className='text-red-500 my-4'>{mut.error.message}</p>}
|
||||||
|
{(mut.isPending && <ButtonLoading />) || (
|
||||||
|
<Button disabled={s.countUrls() == 0} onClick={submit}>
|
||||||
|
{mut.isLoading && <Loader2 className='mr-2 h-4 w-4 animate-spin' />}
|
||||||
|
提交
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default StartScreen
|
105
client/web/src/components/screen/steps.jsx
Normal file
105
client/web/src/components/screen/steps.jsx
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
import { useState, useTransition } from "react"
|
||||||
|
import { Banner } from "@/components/ui/banner"
|
||||||
|
import StepLayout from "@/components/layout/step"
|
||||||
|
import StartScreen from "@/components/screen/start"
|
||||||
|
import ArticlesScreen from "@/components/screen/articles"
|
||||||
|
import InsightsScreen from "@/components/screen/insights"
|
||||||
|
import ReportScreen from "@/components/screen/report"
|
||||||
|
|
||||||
|
import { Loader2 } from "lucide-react"
|
||||||
|
import { useEffect } from "react"
|
||||||
|
import { useClientStore, useData } from "@/store"
|
||||||
|
|
||||||
|
const TITLE = "情报分析"
|
||||||
|
|
||||||
|
function Steps() {
|
||||||
|
let [currentScreen, setCurrentScreen] = useState("/insights")
|
||||||
|
const [isPending, startTransition] = useTransition()
|
||||||
|
const selectInsight = useClientStore((state) => state.selectInsight)
|
||||||
|
const selectedInsight = useClientStore((state) => state.selectedInsight)
|
||||||
|
const taskId = useClientStore((state) => state.taskId)
|
||||||
|
const setTaskId = useClientStore((state) => state.setTaskId)
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// const searchParams = new URLSearchParams(document.location.search)
|
||||||
|
// let taskIdSpecified = searchParams.get("task_id")
|
||||||
|
// if (taskIdSpecified) {
|
||||||
|
// setTaskId(taskIdSpecified)
|
||||||
|
// }
|
||||||
|
// }, [])
|
||||||
|
|
||||||
|
// const query = useData(taskId)
|
||||||
|
// console.log(taskId, query.data)
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// // navigate away from /start
|
||||||
|
// if (query.data && currentScreen == "/start") {
|
||||||
|
// let state = query.data
|
||||||
|
// if (state.articles && Object.keys(state.articles).length > 0) {
|
||||||
|
// setCurrentScreen("/articles")
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (state.insights && Object.keys(state.insights).length > 0) {
|
||||||
|
// if (selectedInsight && state.insights[selectedInsight]?.report?.file) {
|
||||||
|
// setCurrentScreen("/report")
|
||||||
|
// } else {
|
||||||
|
// setCurrentScreen("/insights")
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// selectInsight(null) // deselect
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }, [query.data])
|
||||||
|
|
||||||
|
// const errors = (query.isError && [query.error]) || (query.data && query.data.errors && query.data.errors.length > 0 && query.data.errors)
|
||||||
|
|
||||||
|
function navigate(screen) {
|
||||||
|
startTransition(() => {
|
||||||
|
setCurrentScreen(screen)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log("screen:", currenScreen)
|
||||||
|
|
||||||
|
let content, title
|
||||||
|
if (currentScreen == "/start") {
|
||||||
|
title = TITLE + " > " + "数据来源"
|
||||||
|
content = <StartScreen navigate={navigate} />
|
||||||
|
} else if (currentScreen == "/articles") {
|
||||||
|
title = TITLE + " > " + "文章列表"
|
||||||
|
content = <ArticlesScreen navigate={navigate} />
|
||||||
|
} else if (currentScreen == "/insights") {
|
||||||
|
title = TITLE + " > " + "分析结果"
|
||||||
|
content = <InsightsScreen navigate={navigate} />
|
||||||
|
} else if (currentScreen == "/report") {
|
||||||
|
title = TITLE + " > " + "生成报告"
|
||||||
|
content = <ReportScreen navigate={navigate} />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StepLayout title={title} isPending={isPending} navigate={navigate}>
|
||||||
|
{content}
|
||||||
|
{/* {errors && (
|
||||||
|
<Banner>
|
||||||
|
{errors.map((e, i) => (
|
||||||
|
<p key={i}>{e}</p>
|
||||||
|
))}
|
||||||
|
</Banner>
|
||||||
|
)} */}
|
||||||
|
|
||||||
|
{/* {query.data && query.data.working && (
|
||||||
|
<div className='fixed bottom-2 right-2 text-sm'>
|
||||||
|
<Loader2 className='w-4 h-4 animate-spin text-red-500'></Loader2>
|
||||||
|
</div>
|
||||||
|
)} */}
|
||||||
|
{/* {query.isFetching && (
|
||||||
|
<div className='fixed bottom-2 right-2 text-sm'>
|
||||||
|
<Loader2 className='w-4 h-4 animate-spin'></Loader2>
|
||||||
|
</div>
|
||||||
|
)} */}
|
||||||
|
{/* <div className='left-8 bottom-8 text-sm text-muted-foreground mt-8'>task_id:{taskId}</div> */}
|
||||||
|
</StepLayout>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Steps
|
41
client/web/src/components/ui/accordion.jsx
Normal file
41
client/web/src/components/ui/accordion.jsx
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import * as AccordionPrimitive from "@radix-ui/react-accordion"
|
||||||
|
import { ChevronDown } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const Accordion = AccordionPrimitive.Root
|
||||||
|
|
||||||
|
const AccordionItem = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
|
<AccordionPrimitive.Item ref={ref} className={cn("border-b", className)} {...props} />
|
||||||
|
))
|
||||||
|
AccordionItem.displayName = "AccordionItem"
|
||||||
|
|
||||||
|
const AccordionTrigger = React.forwardRef(({ className, children, ...props }, ref) => (
|
||||||
|
<AccordionPrimitive.Header className="flex">
|
||||||
|
<AccordionPrimitive.Trigger
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}>
|
||||||
|
{children}
|
||||||
|
<ChevronDown className="h-4 w-4 shrink-0 transition-transform duration-200" />
|
||||||
|
</AccordionPrimitive.Trigger>
|
||||||
|
</AccordionPrimitive.Header>
|
||||||
|
))
|
||||||
|
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
|
||||||
|
|
||||||
|
const AccordionContent = React.forwardRef(({ className, children, ...props }, ref) => (
|
||||||
|
<AccordionPrimitive.Content
|
||||||
|
ref={ref}
|
||||||
|
className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
|
||||||
|
{...props}>
|
||||||
|
<div className={cn("pb-4 pt-0", className)}>{children}</div>
|
||||||
|
</AccordionPrimitive.Content>
|
||||||
|
))
|
||||||
|
|
||||||
|
AccordionContent.displayName = AccordionPrimitive.Content.displayName
|
||||||
|
|
||||||
|
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|
9
client/web/src/components/ui/banner.jsx
Normal file
9
client/web/src/components/ui/banner.jsx
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const Banner = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
|
<div className={cn("max-h-24 overflow-y-scroll fixed top-0 right-8 min-w-[200px] max-w-[500px] ml-0 mr-0 bg-red-100 text-red-900 px-6 py-2 border border-red-400 rounded-sm shadow-sm text-sm disabled:cursor-not-allowed", className)} ref={ref} {...props} />
|
||||||
|
))
|
||||||
|
Banner.displayName = "Banner"
|
||||||
|
|
||||||
|
export { Banner }
|
11
client/web/src/components/ui/button-loading.jsx
Normal file
11
client/web/src/components/ui/button-loading.jsx
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Loader2 } from 'lucide-react'
|
||||||
|
|
||||||
|
export function ButtonLoading() {
|
||||||
|
return (
|
||||||
|
<Button disabled>
|
||||||
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||||
|
请稍后
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
47
client/web/src/components/ui/button.jsx
Normal file
47
client/web/src/components/ui/button.jsx
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { Slot } from "@radix-ui/react-slot"
|
||||||
|
import { cva } from "class-variance-authority";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const buttonVariants = cva(
|
||||||
|
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||||
|
destructive:
|
||||||
|
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
||||||
|
outline:
|
||||||
|
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
||||||
|
secondary:
|
||||||
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||||
|
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||||
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
default: "h-10 px-4 py-2",
|
||||||
|
sm: "h-9 rounded-md px-3",
|
||||||
|
lg: "h-11 rounded-md px-8",
|
||||||
|
icon: "h-10 w-10",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const Button = React.forwardRef(({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||||
|
const Comp = asChild ? Slot : "button"
|
||||||
|
return (
|
||||||
|
(<Comp
|
||||||
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
|
ref={ref}
|
||||||
|
{...props} />)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
Button.displayName = "Button"
|
||||||
|
|
||||||
|
export { Button, buttonVariants }
|
133
client/web/src/components/ui/form.jsx
Normal file
133
client/web/src/components/ui/form.jsx
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { Slot } from "@radix-ui/react-slot"
|
||||||
|
import { Controller, FormProvider, useFormContext } from "react-hook-form";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
|
||||||
|
const Form = FormProvider
|
||||||
|
|
||||||
|
const FormFieldContext = React.createContext({})
|
||||||
|
|
||||||
|
const FormField = (
|
||||||
|
{
|
||||||
|
...props
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
(<FormFieldContext.Provider value={{ name: props.name }}>
|
||||||
|
<Controller {...props} />
|
||||||
|
</FormFieldContext.Provider>)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const useFormField = () => {
|
||||||
|
const fieldContext = React.useContext(FormFieldContext)
|
||||||
|
const itemContext = React.useContext(FormItemContext)
|
||||||
|
const { getFieldState, formState } = useFormContext()
|
||||||
|
|
||||||
|
const fieldState = getFieldState(fieldContext.name, formState)
|
||||||
|
|
||||||
|
if (!fieldContext) {
|
||||||
|
throw new Error("useFormField should be used within <FormField>")
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id } = itemContext
|
||||||
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name: fieldContext.name,
|
||||||
|
formItemId: `${id}-form-item`,
|
||||||
|
formDescriptionId: `${id}-form-item-description`,
|
||||||
|
formMessageId: `${id}-form-item-message`,
|
||||||
|
...fieldState,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const FormItemContext = React.createContext({})
|
||||||
|
|
||||||
|
const FormItem = React.forwardRef(({ className, ...props }, ref) => {
|
||||||
|
const id = React.useId()
|
||||||
|
|
||||||
|
return (
|
||||||
|
(<FormItemContext.Provider value={{ id }}>
|
||||||
|
<div ref={ref} className={cn("space-y-2", className)} {...props} />
|
||||||
|
</FormItemContext.Provider>)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
FormItem.displayName = "FormItem"
|
||||||
|
|
||||||
|
const FormLabel = React.forwardRef(({ className, ...props }, ref) => {
|
||||||
|
const { error, formItemId } = useFormField()
|
||||||
|
|
||||||
|
return (
|
||||||
|
(<Label
|
||||||
|
ref={ref}
|
||||||
|
className={cn(error && "text-destructive", className)}
|
||||||
|
htmlFor={formItemId}
|
||||||
|
{...props} />)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
FormLabel.displayName = "FormLabel"
|
||||||
|
|
||||||
|
const FormControl = React.forwardRef(({ ...props }, ref) => {
|
||||||
|
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
|
||||||
|
|
||||||
|
return (
|
||||||
|
(<Slot
|
||||||
|
ref={ref}
|
||||||
|
id={formItemId}
|
||||||
|
aria-describedby={
|
||||||
|
!error
|
||||||
|
? `${formDescriptionId}`
|
||||||
|
: `${formDescriptionId} ${formMessageId}`
|
||||||
|
}
|
||||||
|
aria-invalid={!!error}
|
||||||
|
{...props} />)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
FormControl.displayName = "FormControl"
|
||||||
|
|
||||||
|
const FormDescription = React.forwardRef(({ className, ...props }, ref) => {
|
||||||
|
const { formDescriptionId } = useFormField()
|
||||||
|
|
||||||
|
return (
|
||||||
|
(<p
|
||||||
|
ref={ref}
|
||||||
|
id={formDescriptionId}
|
||||||
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
|
{...props} />)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
FormDescription.displayName = "FormDescription"
|
||||||
|
|
||||||
|
const FormMessage = React.forwardRef(({ className, children, ...props }, ref) => {
|
||||||
|
const { error, formMessageId } = useFormField()
|
||||||
|
const body = error ? String(error?.message) : children
|
||||||
|
|
||||||
|
if (!body) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
(<p
|
||||||
|
ref={ref}
|
||||||
|
id={formMessageId}
|
||||||
|
className={cn("text-sm font-medium text-destructive", className)}
|
||||||
|
{...props}>
|
||||||
|
{body}
|
||||||
|
</p>)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
FormMessage.displayName = "FormMessage"
|
||||||
|
|
||||||
|
export {
|
||||||
|
useFormField,
|
||||||
|
Form,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormControl,
|
||||||
|
FormDescription,
|
||||||
|
FormMessage,
|
||||||
|
FormField,
|
||||||
|
}
|
19
client/web/src/components/ui/input.jsx
Normal file
19
client/web/src/components/ui/input.jsx
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const Input = React.forwardRef(({ className, type, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
(<input
|
||||||
|
type={type}
|
||||||
|
className={cn(
|
||||||
|
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
ref={ref}
|
||||||
|
{...props} />)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
Input.displayName = "Input"
|
||||||
|
|
||||||
|
export { Input }
|
16
client/web/src/components/ui/label.jsx
Normal file
16
client/web/src/components/ui/label.jsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import * as LabelPrimitive from "@radix-ui/react-label"
|
||||||
|
import { cva } from "class-variance-authority";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const labelVariants = cva(
|
||||||
|
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||||
|
)
|
||||||
|
|
||||||
|
const Label = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
|
<LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} />
|
||||||
|
))
|
||||||
|
Label.displayName = LabelPrimitive.Root.displayName
|
||||||
|
|
||||||
|
export { Label }
|
18
client/web/src/components/ui/textarea.jsx
Normal file
18
client/web/src/components/ui/textarea.jsx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const Textarea = React.forwardRef(({ className, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
(<textarea
|
||||||
|
className={cn(
|
||||||
|
"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
ref={ref}
|
||||||
|
{...props} />)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
Textarea.displayName = "Textarea"
|
||||||
|
|
||||||
|
export { Textarea }
|
82
client/web/src/components/ui/toast.jsx
Normal file
82
client/web/src/components/ui/toast.jsx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import * as ToastPrimitives from "@radix-ui/react-toast"
|
||||||
|
import { cva } from "class-variance-authority";
|
||||||
|
import { X } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const ToastProvider = ToastPrimitives.Provider
|
||||||
|
|
||||||
|
const ToastViewport = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
|
<ToastPrimitives.Viewport
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props} />
|
||||||
|
))
|
||||||
|
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
|
||||||
|
|
||||||
|
const toastVariants = cva(
|
||||||
|
"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "border bg-background text-foreground",
|
||||||
|
destructive:
|
||||||
|
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const Toast = React.forwardRef(({ className, variant, ...props }, ref) => {
|
||||||
|
return (
|
||||||
|
(<ToastPrimitives.Root
|
||||||
|
ref={ref}
|
||||||
|
className={cn(toastVariants({ variant }), className)}
|
||||||
|
{...props} />)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
Toast.displayName = ToastPrimitives.Root.displayName
|
||||||
|
|
||||||
|
const ToastAction = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
|
<ToastPrimitives.Action
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props} />
|
||||||
|
))
|
||||||
|
ToastAction.displayName = ToastPrimitives.Action.displayName
|
||||||
|
|
||||||
|
const ToastClose = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
|
<ToastPrimitives.Close
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
toast-close=""
|
||||||
|
{...props}>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</ToastPrimitives.Close>
|
||||||
|
))
|
||||||
|
ToastClose.displayName = ToastPrimitives.Close.displayName
|
||||||
|
|
||||||
|
const ToastTitle = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
|
<ToastPrimitives.Title ref={ref} className={cn("text-sm font-semibold", className)} {...props} />
|
||||||
|
))
|
||||||
|
ToastTitle.displayName = ToastPrimitives.Title.displayName
|
||||||
|
|
||||||
|
const ToastDescription = React.forwardRef(({ className, ...props }, ref) => (
|
||||||
|
<ToastPrimitives.Description ref={ref} className={cn("text-sm opacity-90", className)} {...props} />
|
||||||
|
))
|
||||||
|
ToastDescription.displayName = ToastPrimitives.Description.displayName
|
||||||
|
|
||||||
|
export { ToastProvider, ToastViewport, Toast, ToastTitle, ToastDescription, ToastClose, ToastAction };
|
33
client/web/src/components/ui/toaster.jsx
Normal file
33
client/web/src/components/ui/toaster.jsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import {
|
||||||
|
Toast,
|
||||||
|
ToastClose,
|
||||||
|
ToastDescription,
|
||||||
|
ToastProvider,
|
||||||
|
ToastTitle,
|
||||||
|
ToastViewport,
|
||||||
|
} from "@/components/ui/toast"
|
||||||
|
import { useToast } from "@/components/ui/use-toast"
|
||||||
|
|
||||||
|
export function Toaster() {
|
||||||
|
const { toasts } = useToast()
|
||||||
|
|
||||||
|
return (
|
||||||
|
(<ToastProvider>
|
||||||
|
{toasts.map(function ({ id, title, description, action, ...props }) {
|
||||||
|
return (
|
||||||
|
(<Toast key={id} {...props}>
|
||||||
|
<div className="grid gap-1">
|
||||||
|
{title && <ToastTitle>{title}</ToastTitle>}
|
||||||
|
{description && (
|
||||||
|
<ToastDescription>{description}</ToastDescription>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{action}
|
||||||
|
<ToastClose />
|
||||||
|
</Toast>)
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<ToastViewport />
|
||||||
|
</ToastProvider>)
|
||||||
|
);
|
||||||
|
}
|
154
client/web/src/components/ui/use-toast.js
Normal file
154
client/web/src/components/ui/use-toast.js
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
// Inspired by react-hot-toast library
|
||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
const TOAST_LIMIT = 1
|
||||||
|
const TOAST_REMOVE_DELAY = 1000000
|
||||||
|
|
||||||
|
const actionTypes = {
|
||||||
|
ADD_TOAST: "ADD_TOAST",
|
||||||
|
UPDATE_TOAST: "UPDATE_TOAST",
|
||||||
|
DISMISS_TOAST: "DISMISS_TOAST",
|
||||||
|
REMOVE_TOAST: "REMOVE_TOAST"
|
||||||
|
}
|
||||||
|
|
||||||
|
let count = 0
|
||||||
|
|
||||||
|
function genId() {
|
||||||
|
count = (count + 1) % Number.MAX_SAFE_INTEGER
|
||||||
|
return count.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
const toastTimeouts = new Map()
|
||||||
|
|
||||||
|
const addToRemoveQueue = (toastId) => {
|
||||||
|
if (toastTimeouts.has(toastId)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
toastTimeouts.delete(toastId)
|
||||||
|
dispatch({
|
||||||
|
type: "REMOVE_TOAST",
|
||||||
|
toastId: toastId,
|
||||||
|
})
|
||||||
|
}, TOAST_REMOVE_DELAY)
|
||||||
|
|
||||||
|
toastTimeouts.set(toastId, timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const reducer = (state, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case "ADD_TOAST":
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
||||||
|
};
|
||||||
|
|
||||||
|
case "UPDATE_TOAST":
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: state.toasts.map((t) =>
|
||||||
|
t.id === action.toast.id ? { ...t, ...action.toast } : t),
|
||||||
|
};
|
||||||
|
|
||||||
|
case "DISMISS_TOAST": {
|
||||||
|
const { toastId } = action
|
||||||
|
|
||||||
|
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
||||||
|
// but I'll keep it here for simplicity
|
||||||
|
if (toastId) {
|
||||||
|
addToRemoveQueue(toastId)
|
||||||
|
} else {
|
||||||
|
state.toasts.forEach((toast) => {
|
||||||
|
addToRemoveQueue(toast.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: state.toasts.map((t) =>
|
||||||
|
t.id === toastId || toastId === undefined
|
||||||
|
? {
|
||||||
|
...t,
|
||||||
|
open: false,
|
||||||
|
}
|
||||||
|
: t),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case "REMOVE_TOAST":
|
||||||
|
if (action.toastId === undefined) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const listeners = []
|
||||||
|
|
||||||
|
let memoryState = { toasts: [] }
|
||||||
|
|
||||||
|
function dispatch(action) {
|
||||||
|
memoryState = reducer(memoryState, action)
|
||||||
|
listeners.forEach((listener) => {
|
||||||
|
listener(memoryState)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function toast({
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
|
const id = genId()
|
||||||
|
|
||||||
|
const update = (props) =>
|
||||||
|
dispatch({
|
||||||
|
type: "UPDATE_TOAST",
|
||||||
|
toast: { ...props, id },
|
||||||
|
})
|
||||||
|
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id })
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: "ADD_TOAST",
|
||||||
|
toast: {
|
||||||
|
...props,
|
||||||
|
id,
|
||||||
|
open: true,
|
||||||
|
onOpenChange: (open) => {
|
||||||
|
if (!open) dismiss()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: id,
|
||||||
|
dismiss,
|
||||||
|
update,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function useToast() {
|
||||||
|
const [state, setState] = React.useState(memoryState)
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
listeners.push(setState)
|
||||||
|
return () => {
|
||||||
|
const index = listeners.indexOf(setState)
|
||||||
|
if (index > -1) {
|
||||||
|
listeners.splice(index, 1)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [state])
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
toast,
|
||||||
|
dismiss: (toastId) => dispatch({ type: "DISMISS_TOAST", toastId }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export { useToast, toast }
|
82
client/web/src/index.css
Normal file
82
client/web/src/index.css
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
:root {
|
||||||
|
--background: 0 0% 100%;
|
||||||
|
--foreground: 222.2 84% 4.9%;
|
||||||
|
|
||||||
|
--card: 0 0% 100%;
|
||||||
|
--card-foreground: 222.2 84% 4.9%;
|
||||||
|
|
||||||
|
--popover: 0 0% 100%;
|
||||||
|
--popover-foreground: 222.2 84% 4.9%;
|
||||||
|
|
||||||
|
--primary: 222.2 47.4% 11.2%;
|
||||||
|
--primary-foreground: 210 40% 98%;
|
||||||
|
|
||||||
|
--secondary: 210 40% 96.1%;
|
||||||
|
--secondary-foreground: 222.2 47.4% 11.2%;
|
||||||
|
|
||||||
|
--muted: 210 40% 96.1%;
|
||||||
|
--muted-foreground: 215.4 16.3% 46.9%;
|
||||||
|
|
||||||
|
--accent: 210 40% 96.1%;
|
||||||
|
--accent-foreground: 222.2 47.4% 11.2%;
|
||||||
|
|
||||||
|
--destructive: 0 84.2% 60.2%;
|
||||||
|
--destructive-foreground: 210 40% 98%;
|
||||||
|
|
||||||
|
--border: 214.3 31.8% 91.4%;
|
||||||
|
--input: 214.3 31.8% 91.4%;
|
||||||
|
--ring: 222.2 84% 4.9%;
|
||||||
|
|
||||||
|
--radius: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
--background: 222.2 84% 4.9%;
|
||||||
|
--foreground: 210 40% 98%;
|
||||||
|
|
||||||
|
--card: 222.2 84% 4.9%;
|
||||||
|
--card-foreground: 210 40% 98%;
|
||||||
|
|
||||||
|
--popover: 222.2 84% 4.9%;
|
||||||
|
--popover-foreground: 210 40% 98%;
|
||||||
|
|
||||||
|
--primary: 210 40% 98%;
|
||||||
|
--primary-foreground: 222.2 47.4% 11.2%;
|
||||||
|
|
||||||
|
--secondary: 217.2 32.6% 17.5%;
|
||||||
|
--secondary-foreground: 210 40% 98%;
|
||||||
|
|
||||||
|
--muted: 217.2 32.6% 17.5%;
|
||||||
|
--muted-foreground: 215 20.2% 65.1%;
|
||||||
|
|
||||||
|
--accent: 217.2 32.6% 17.5%;
|
||||||
|
--accent-foreground: 210 40% 98%;
|
||||||
|
|
||||||
|
--destructive: 0 62.8% 30.6%;
|
||||||
|
--destructive-foreground: 210 40% 98%;
|
||||||
|
|
||||||
|
--border: 217.2 32.6% 17.5%;
|
||||||
|
--input: 217.2 32.6% 17.5%;
|
||||||
|
--ring: 212.7 26.8% 83.9%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
* {
|
||||||
|
@apply border-border;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
@apply bg-background text-foreground;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer components {
|
||||||
|
h2 {
|
||||||
|
@apply scroll-m-20 text-2xl font-semibold tracking-tight mb-4;
|
||||||
|
}
|
||||||
|
}
|
18
client/web/src/lib/utils.js
Normal file
18
client/web/src/lib/utils.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { clsx } from "clsx"
|
||||||
|
import { twMerge } from "tailwind-merge"
|
||||||
|
|
||||||
|
export function cn(...inputs) {
|
||||||
|
return twMerge(clsx(inputs))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatDate(date) {
|
||||||
|
var d = new Date(isNaN(date) ? date + "T00:00:00" : date)
|
||||||
|
var iso = d.toISOString()
|
||||||
|
return iso.slice(0, 10) + " " + iso.slice(11, 23) + "Z"
|
||||||
|
// return [d.getFullYear(), (d.getMonth() + 1).padLeft(), d.getDate().padLeft()].join("-") + " " + [d.getHours().padLeft(), d.getMinutes().padLeft(), d.getSeconds().padLeft()].join(":") + ".000Z"
|
||||||
|
}
|
||||||
|
|
||||||
|
Number.prototype.padLeft = function (base, chr) {
|
||||||
|
var len = String(base || 10).length - String(this).length + 1
|
||||||
|
return len > 0 ? new Array(len).join(chr || "0") + this : this
|
||||||
|
}
|
10
client/web/src/main.jsx
Normal file
10
client/web/src/main.jsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import ReactDOM from 'react-dom/client'
|
||||||
|
import App from './App.jsx'
|
||||||
|
import './index.css'
|
||||||
|
|
||||||
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>,
|
||||||
|
)
|
273
client/web/src/store.js
Normal file
273
client/web/src/store.js
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
import { useEffect, useState } from "react"
|
||||||
|
import PocketBase from "pocketbase"
|
||||||
|
const pb = new PocketBase(import.meta.env.VITE_PB_BASE)
|
||||||
|
import { useQuery } from "@tanstack/react-query"
|
||||||
|
|
||||||
|
import { create } from "zustand"
|
||||||
|
import { persist } from "zustand/middleware"
|
||||||
|
// import axios from "redaxios"
|
||||||
|
import axios from "axios"
|
||||||
|
import { nanoid } from "nanoid"
|
||||||
|
|
||||||
|
import { formatDate } from "./lib/utils"
|
||||||
|
|
||||||
|
const DAYS_RANGE = [1, 14]
|
||||||
|
|
||||||
|
export const useClientStore = create(
|
||||||
|
persist(
|
||||||
|
(set, get) => ({
|
||||||
|
taskId: "",
|
||||||
|
urls: ["https://cyberscoop.com"],
|
||||||
|
days: 14,
|
||||||
|
workflow_name: "情报分析",
|
||||||
|
toc: ["参考情报", "基本内容", "相关发声情况", "应对策略"],
|
||||||
|
selectedInsight: null,
|
||||||
|
comment: "",
|
||||||
|
|
||||||
|
setTaskId: (taskId) => set({ taskId }),
|
||||||
|
setUrls: (urls) => set({ urls }),
|
||||||
|
countUrls: () => get().urls.filter((url) => url).length,
|
||||||
|
selectInsight: (id) => set({ selectedInsight: id }),
|
||||||
|
updateToc: (value) => set({ toc: value }),
|
||||||
|
updateComment: (value) => set({ comment: value }),
|
||||||
|
incr: () => set((state) => ({ days: state.days + 1 > DAYS_RANGE[1] ? DAYS_RANGE[1] : state.days + 1 })),
|
||||||
|
decr: () => set((state) => ({ days: state.days - 1 < DAYS_RANGE[0] ? DAYS_RANGE[0] : state.days - 1 })),
|
||||||
|
minDays: () => get().days === DAYS_RANGE[0],
|
||||||
|
maxDays: () => get().days === DAYS_RANGE[1],
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
version: "0.1.1",
|
||||||
|
name: "aw-storage",
|
||||||
|
// storage: createJSONStorage(() => sessionStorage), // (optional) by default, 'localStorage' is used
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
export function login({ username, password }) {
|
||||||
|
//return pb.collection("users").authWithPassword(username, password)
|
||||||
|
return pb.admins.authWithPassword(username, password)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isAuth() {
|
||||||
|
return pb.authStore.isValid
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useData(task_id, autoRefetch = undefined) {
|
||||||
|
let interval = parseInt(autoRefetch) >= 1000 ? parseInt(autoRefetch) : undefined
|
||||||
|
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["data", task_id ? task_id : ""],
|
||||||
|
queryFn: () => data(task_id ? task_id : ""),
|
||||||
|
refetchInterval: (query) => {
|
||||||
|
//console.log(query)
|
||||||
|
if (!query.state.data || (query.state.data && query.state.data.working)) {
|
||||||
|
return interval
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createTask({ id, urls, days }) {
|
||||||
|
let from = new Date()
|
||||||
|
from.setHours(0, 0, 0, 0)
|
||||||
|
from.setDate(from.getDate() - days)
|
||||||
|
|
||||||
|
let fromStr = from.toISOString().slice(0, 10).split("-").join("")
|
||||||
|
let task_id = id || nanoid(10)
|
||||||
|
console.log("creating task: ", task_id, urls.filter((url) => url).length + " sites", fromStr)
|
||||||
|
|
||||||
|
if (urls.length == 0) {
|
||||||
|
urls.push("")
|
||||||
|
}
|
||||||
|
|
||||||
|
return axios({
|
||||||
|
method: "post",
|
||||||
|
url: `${import.meta.env.VITE_API_BASE}/sites`,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
after: fromStr,
|
||||||
|
sites: urls,
|
||||||
|
task_id: task_id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
useClientStore.getState().setTaskId(task_id)
|
||||||
|
return response
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
useClientStore.getState().setTaskId("")
|
||||||
|
return error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function report({ task_id, insight_id, toc, comment }) {
|
||||||
|
return axios({
|
||||||
|
method: "post",
|
||||||
|
url: `${import.meta.env.VITE_API_BASE}/report`,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
task_id: task_id,
|
||||||
|
toc: toc,
|
||||||
|
insight_id: insight_id,
|
||||||
|
comment: comment,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function more({ insight_id }) {
|
||||||
|
return axios({
|
||||||
|
method: "post",
|
||||||
|
url: `${import.meta.env.VITE_API_BASE}/search_for_insight`,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
//toc: toc,
|
||||||
|
insight_id: insight_id,
|
||||||
|
//comment: comment,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function translations({ article_ids }) {
|
||||||
|
return axios({
|
||||||
|
method: "post",
|
||||||
|
url: `${import.meta.env.VITE_API_BASE}/translations`,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
article_ids,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useArticles(date) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["articles", date],
|
||||||
|
queryFn: () => getArticles(date),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useInsight(id) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["insight", id],
|
||||||
|
queryFn: () => getInsight(id),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useInsights(date) {
|
||||||
|
const { data = [] } = useQuery({
|
||||||
|
queryKey: ["insights", date],
|
||||||
|
queryFn: () => getInsights(date),
|
||||||
|
})
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useInsightDates() {
|
||||||
|
const { data = [] } = useQuery({
|
||||||
|
queryKey: ["insight_dates"],
|
||||||
|
queryFn: getInsightDates,
|
||||||
|
})
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useArticleDates() {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["article_dates"],
|
||||||
|
queryFn: () => getArticleDates(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDatePager(dates) {
|
||||||
|
const [index, setIndex] = useState(-1)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (index < 0 && dates) {
|
||||||
|
setIndex(dates.length - 1)
|
||||||
|
}
|
||||||
|
}, [index, dates])
|
||||||
|
|
||||||
|
const hasLast = () => index > 0
|
||||||
|
const hasNext = () => index >= 0 && index < dates.length - 1
|
||||||
|
const last = () => hasLast() && setIndex(index - 1)
|
||||||
|
const next = () => hasNext() && setIndex(index + 1)
|
||||||
|
|
||||||
|
return {
|
||||||
|
index,
|
||||||
|
last,
|
||||||
|
next,
|
||||||
|
hasLast,
|
||||||
|
hasNext,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getArticles(date) {
|
||||||
|
if (!date) return []
|
||||||
|
|
||||||
|
const from = formatDate(date)
|
||||||
|
const to = formatDate(new Date(new Date(date).getTime() + 60 * 60 * 24 * 1000))
|
||||||
|
return pb.collection("articles").getFullList({
|
||||||
|
sort: "-created",
|
||||||
|
expand: "translation_result",
|
||||||
|
filter: 'created >= "' + from + '" && created < "' + to + '"',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getInsight(id) {
|
||||||
|
return pb.collection("insights").getOne(id, { expand: "docx" })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getInsights(date) {
|
||||||
|
if (!date) return null
|
||||||
|
|
||||||
|
const from = formatDate(date)
|
||||||
|
const to = formatDate(new Date(new Date(date + "T00:00:00").getTime() + 60 * 60 * 24 * 1000))
|
||||||
|
// console.log("from/to", from, to)
|
||||||
|
|
||||||
|
const f = 'created >= "' + from + '" && created < "' + to + '"'
|
||||||
|
console.log(f)
|
||||||
|
|
||||||
|
return pb.collection("insights").getFullList({
|
||||||
|
sort: "-created",
|
||||||
|
expand: "articles, articles.translation_result",
|
||||||
|
// expand: "articles",
|
||||||
|
filter: f,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getInsightDates() {
|
||||||
|
const { data } = await axios({
|
||||||
|
method: "get",
|
||||||
|
url: `${import.meta.env.VITE_PB_BASE}/insight_dates`,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + pb.authStore?.token,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
// return data.map((d) => new Date(d + "T00:00:00Z").toLocaleDateString().split("/").join("-"))
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getArticleDates() {
|
||||||
|
let { data } = await axios({
|
||||||
|
method: "get",
|
||||||
|
url: `${import.meta.env.VITE_PB_BASE}/article_dates`,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + pb.authStore?.token,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unlinkArticle({ insight_id, article_id }) {
|
||||||
|
return pb.collection("insights").update(insight_id, {
|
||||||
|
"articles-": article_id,
|
||||||
|
})
|
||||||
|
}
|
77
client/web/tailwind.config.js
Normal file
77
client/web/tailwind.config.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
module.exports = {
|
||||||
|
darkMode: ["class"],
|
||||||
|
content: [
|
||||||
|
'./pages/**/*.{js,jsx}',
|
||||||
|
'./components/**/*.{js,jsx}',
|
||||||
|
'./app/**/*.{js,jsx}',
|
||||||
|
'./src/**/*.{js,jsx}',
|
||||||
|
],
|
||||||
|
prefix: "",
|
||||||
|
theme: {
|
||||||
|
container: {
|
||||||
|
center: true,
|
||||||
|
padding: "2rem",
|
||||||
|
screens: {
|
||||||
|
"2xl": "1400px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
extend: {
|
||||||
|
colors: {
|
||||||
|
border: "hsl(var(--border))",
|
||||||
|
input: "hsl(var(--input))",
|
||||||
|
ring: "hsl(var(--ring))",
|
||||||
|
background: "hsl(var(--background))",
|
||||||
|
foreground: "hsl(var(--foreground))",
|
||||||
|
primary: {
|
||||||
|
DEFAULT: "hsl(var(--primary))",
|
||||||
|
foreground: "hsl(var(--primary-foreground))",
|
||||||
|
},
|
||||||
|
secondary: {
|
||||||
|
DEFAULT: "hsl(var(--secondary))",
|
||||||
|
foreground: "hsl(var(--secondary-foreground))",
|
||||||
|
},
|
||||||
|
destructive: {
|
||||||
|
DEFAULT: "hsl(var(--destructive))",
|
||||||
|
foreground: "hsl(var(--destructive-foreground))",
|
||||||
|
},
|
||||||
|
muted: {
|
||||||
|
DEFAULT: "hsl(var(--muted))",
|
||||||
|
foreground: "hsl(var(--muted-foreground))",
|
||||||
|
},
|
||||||
|
accent: {
|
||||||
|
DEFAULT: "hsl(var(--accent))",
|
||||||
|
foreground: "hsl(var(--accent-foreground))",
|
||||||
|
},
|
||||||
|
popover: {
|
||||||
|
DEFAULT: "hsl(var(--popover))",
|
||||||
|
foreground: "hsl(var(--popover-foreground))",
|
||||||
|
},
|
||||||
|
card: {
|
||||||
|
DEFAULT: "hsl(var(--card))",
|
||||||
|
foreground: "hsl(var(--card-foreground))",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
borderRadius: {
|
||||||
|
lg: "var(--radius)",
|
||||||
|
md: "calc(var(--radius) - 2px)",
|
||||||
|
sm: "calc(var(--radius) - 4px)",
|
||||||
|
},
|
||||||
|
keyframes: {
|
||||||
|
"accordion-down": {
|
||||||
|
from: { height: "0" },
|
||||||
|
to: { height: "var(--radix-accordion-content-height)" },
|
||||||
|
},
|
||||||
|
"accordion-up": {
|
||||||
|
from: { height: "var(--radix-accordion-content-height)" },
|
||||||
|
to: { height: "0" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
animation: {
|
||||||
|
"accordion-down": "accordion-down 0.2s ease-out",
|
||||||
|
"accordion-up": "accordion-up 0.2s ease-out",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: [require("tailwindcss-animate")],
|
||||||
|
}
|
8
client/web/tsconfig.json
Normal file
8
client/web/tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
client/web/vite.config.js
Normal file
15
client/web/vite.config.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import path from "path"
|
||||||
|
import * as child from "child_process"
|
||||||
|
import { defineConfig } from "vite"
|
||||||
|
import react from "@vitejs/plugin-react"
|
||||||
|
// const commitHash = child.execSync('git rev-parse --short HEAD').toString()
|
||||||
|
// https://vitejs.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"@": path.resolve(__dirname, "./src"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// define: { 'import.meta.env.VITE_APP_VERSION': JSON.stringify(commitHash) },
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user