Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
ee718750
authored
Oct 29, 2024
by
Archer
Committed by
GitHub
Oct 29, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: dataset data auth (#3015)
parent
1e02544c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
48 deletions
+51
-48
packages/global/core/dataset/type.d.ts
+2
-2
packages/service/support/permission/dataset/auth.ts
+49
-45
projects/app/src/pages/api/core/dataset/data/update.ts
+0
-1
No files found.
packages/global/core/dataset/type.d.ts
View file @
ee718750
...
@@ -191,7 +191,7 @@ export type DatasetDataItemType = {
...
@@ -191,7 +191,7 @@ export type DatasetDataItemType = {
chunkIndex
:
number
;
chunkIndex
:
number
;
indexes
:
DatasetDataIndexItemType
[];
indexes
:
DatasetDataIndexItemType
[];
isOwner
:
boolean
;
isOwner
:
boolean
;
canWrite
:
boolea
n
;
// permission: DatasetPermissio
n;
};
};
/* --------------- file ---------------------- */
/* --------------- file ---------------------- */
...
@@ -212,7 +212,7 @@ export type DatasetFileSchema = {
...
@@ -212,7 +212,7 @@ export type DatasetFileSchema = {
/* ============= search =============== */
/* ============= search =============== */
export
type
SearchDataResponseItemType
=
Omit
<
export
type
SearchDataResponseItemType
=
Omit
<
DatasetDataItemType
,
DatasetDataItemType
,
'teamId'
|
'indexes'
|
'isOwner'
|
'canWrite'
'teamId'
|
'indexes'
|
'isOwner'
>
&
{
>
&
{
score
:
{
type
:
`
${
SearchScoreTypeEnum
}
`
;
value
:
number
;
index
:
number
}[];
score
:
{
type
:
`
${
SearchScoreTypeEnum
}
`
;
value
:
number
;
index
:
number
}[];
// score: number;
// score: number;
...
...
packages/service/support/permission/dataset/auth.ts
View file @
ee718750
...
@@ -157,6 +157,7 @@ export const authDataset = async ({
...
@@ -157,6 +157,7 @@ export const authDataset = async ({
dataset
dataset
};
};
};
};
// the temporary solution for authDatasetCollection is getting the
// the temporary solution for authDatasetCollection is getting the
export
async
function
authDatasetCollection
({
export
async
function
authDatasetCollection
({
collectionId
,
collectionId
,
...
@@ -194,55 +195,58 @@ export async function authDatasetCollection({
...
@@ -194,55 +195,58 @@ export async function authDatasetCollection({
};
};
}
}
export
async
function
authDatasetFile
({
//
export async function authDatasetFile({
fileId
,
//
fileId,
per
,
//
per,
...
props
//
...props
}:
AuthModeType
&
{
//
}: AuthModeType & {
fileId
:
string
;
//
fileId: string;
}):
Promise
<
//
}): Promise<
AuthResponseType
<
DatasetPermission
>
&
{
//
AuthResponseType<DatasetPermission> & {
file
:
DatasetFileSchema
;
//
file: DatasetFileSchema;
}
//
}
>
{
//
> {
const
{
teamId
,
tmbId
,
isRoot
}
=
await
parseHeaderCert
(
props
);
//
const { teamId, tmbId, isRoot } = await parseHeaderCert(props);
const
[
file
,
collection
]
=
await
Promise
.
all
([
//
const [file, collection] = await Promise.all([
getFileById
({
bucketName
:
BucketNameEnum
.
dataset
,
fileId
}),
//
getFileById({ bucketName: BucketNameEnum.dataset, fileId }),
MongoDatasetCollection
.
findOne
({
//
MongoDatasetCollection.findOne({
teamId
,
//
teamId,
fileId
//
fileId
})
//
})
]);
//
]);
if
(
!
file
)
{
//
if (!file) {
return
Promise
.
reject
(
CommonErrEnum
.
fileNotFound
);
//
return Promise.reject(CommonErrEnum.fileNotFound);
}
//
}
if
(
!
collection
)
{
//
if (!collection) {
return
Promise
.
reject
(
DatasetErrEnum
.
unAuthDatasetFile
);
//
return Promise.reject(DatasetErrEnum.unAuthDatasetFile);
}
//
}
try
{
//
try {
const
{
permission
}
=
await
authDatasetCollection
({
//
const { permission } = await authDatasetCollection({
...
props
,
//
...props,
collectionId
:
collection
.
_id
,
//
collectionId: collection._id,
per
,
//
per,
isRoot
//
isRoot
});
//
});
return
{
//
return {
teamId
,
//
teamId,
tmbId
,
//
tmbId,
file
,
//
file,
permission
,
//
permission,
isRoot
//
isRoot
};
//
};
}
catch
(
error
)
{
//
} catch (error) {
return
Promise
.
reject
(
DatasetErrEnum
.
unAuthDatasetFile
);
//
return Promise.reject(DatasetErrEnum.unAuthDatasetFile);
}
//
}
}
//
}
/*
DatasetData permission is inherited from collection.
*/
export
async
function
authDatasetData
({
export
async
function
authDatasetData
({
dataId
,
dataId
,
...
props
...
props
...
@@ -273,8 +277,8 @@ export async function authDatasetData({
...
@@ -273,8 +277,8 @@ export async function authDatasetData({
collectionId
:
String
(
datasetData
.
collectionId
),
collectionId
:
String
(
datasetData
.
collectionId
),
sourceName
:
result
.
collection
.
name
||
''
,
sourceName
:
result
.
collection
.
name
||
''
,
sourceId
:
result
.
collection
?.
fileId
||
result
.
collection
?.
rawLink
,
sourceId
:
result
.
collection
?.
fileId
||
result
.
collection
?.
rawLink
,
isOwner
:
String
(
datasetData
.
tmbId
)
===
String
(
result
.
tmbId
)
,
isOwner
:
String
(
datasetData
.
tmbId
)
===
String
(
result
.
tmbId
)
canWrite
:
result
.
permission
.
hasWritePer
// permission: result.permission
};
};
return
{
return
{
...
...
projects/app/src/pages/api/core/dataset/data/update.ts
View file @
ee718750
...
@@ -5,7 +5,6 @@ import { NextAPI } from '@/service/middleware/entry';
...
@@ -5,7 +5,6 @@ import { NextAPI } from '@/service/middleware/entry';
import
{
WritePermissionVal
}
from
'@fastgpt/global/support/permission/constant'
;
import
{
WritePermissionVal
}
from
'@fastgpt/global/support/permission/constant'
;
import
{
authDatasetData
}
from
'@fastgpt/service/support/permission/dataset/auth'
;
import
{
authDatasetData
}
from
'@fastgpt/service/support/permission/dataset/auth'
;
import
{
ApiRequestProps
}
from
'@fastgpt/service/type/next'
;
import
{
ApiRequestProps
}
from
'@fastgpt/service/type/next'
;
import
{
MongoDatasetData
}
from
'@fastgpt/service/core/dataset/data/schema'
;
async
function
handler
(
req
:
ApiRequestProps
<
UpdateDatasetDataProps
>
)
{
async
function
handler
(
req
:
ApiRequestProps
<
UpdateDatasetDataProps
>
)
{
const
{
dataId
,
q
,
a
,
indexes
=
[]
}
=
req
.
body
;
const
{
dataId
,
q
,
a
,
indexes
=
[]
}
=
req
.
body
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment