Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appbase-edge-function
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanjinfei
appbase-edge-function
Commits
d7bbf06b
Commit
d7bbf06b
authored
Dec 12, 2024
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add crawl-data function
parent
f53bfa3f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
4 deletions
+37
-4
cli-latest
supabase/.temp/cli-latest
+1
-1
index.ts
supabase/functions/update-app/index.ts
+36
-3
No files found.
supabase/.temp/cli-latest
View file @
d7bbf06b
v1.223.10
\ No newline at end of file
v2.0.0
\ No newline at end of file
supabase/functions/update-app/index.ts
View file @
d7bbf06b
...
...
@@ -15,7 +15,8 @@ async function fetchAllData(supabase, table: string, pageSize: number = 1000) {
const
{
data
,
error
}
=
await
supabase
.
from
(
table
)
.
select
(
'
*
'
)
// 可以根据需要调整字段
.
eq
(
'
is_show
'
,
true
)
.
gt
(
'
is_show
'
,
0
)
// .eq('is_show', 1)
.
order
(
'
created_at
'
,
{
ascending
:
true
})
// 按照创建时间排序
.
range
(
offset
,
offset
+
pageSize
-
1
);
// 分页范围
...
...
@@ -52,7 +53,6 @@ Deno.serve(async (req) => {
Deno
.
env
.
get
(
'
SUPABASE_ANON_KEY
'
)
??
''
,
{
global
:
{
headers
:
{
Authorization
:
req
.
headers
.
get
(
'
Authorization
'
)
!
}
}
}
)
// 获取所有 app 数据
const
allApps
=
await
fetchAllData
(
supabase
,
'
app
'
);
// 获取当前时间的整点时间戳
...
...
@@ -95,6 +95,40 @@ Deno.serve(async (req) => {
}
}
const
recommandPageSize
=
3
;
const
recommandApps
=
allApps
.
filter
(
app
=>
app
.
recommand
>
0
);
const
recommandTotalCount
=
recommandApps
.
length
;
const
recommandPaginatedApps
=
[];
for
(
let
i
=
0
;
i
<
recommandTotalCount
;
i
+=
recommandPageSize
)
{
recommandPaginatedApps
.
push
(
recommandApps
.
slice
(
i
,
i
+
recommandPageSize
));
}
// 遍历分页后的数据并上传
for
(
let
pageNum
=
1
;
pageNum
<=
recommandPageSize
.
length
;
pageNum
++
)
{
const
pageApps
=
recommandPageSize
[
pageNum
-
1
];
const
pageJson
=
JSON
.
stringify
({
total_count
:
recommandTotalCount
,
apps
:
pageApps
,
});
const
pageFileName
=
`
${
directory
}
/app_recommand_
${
pageNum
}
.json`
;
const
{
error
:
pageUploadError
}
=
await
supabase
.
storage
.
from
(
bucketName
)
.
upload
(
pageFileName
,
new
Blob
([
pageJson
]),
{
contentType
:
'
application/json
'
,
upsert
:
true
,
});
if
(
pageUploadError
)
{
console
.
error
(
`Error uploading page
${
pageNum
}
JSON:`
,
pageUploadError
);
return
new
Response
(
JSON
.
stringify
({
error
:
`Failed to upload app_recommand_
${
pageNum
}
.json`
}),
{
status
:
500
}
);
}
}
// 按 category_id 分组
const
groupedData
:
Record
<
string
,
any
[]
>
=
{};
allApps
.
forEach
((
app
)
=>
{
...
...
@@ -104,7 +138,6 @@ Deno.serve(async (req) => {
groupedData
[
app
.
category_id
].
push
(
app
);
});
// 上传每个 category_id 的数据
// 上传每个 category_id 的分页数据
for
(
const
[
categoryId
,
apps
]
of
Object
.
entries
(
groupedData
))
{
const
totalCount
=
apps
.
length
;
// 当前分类的总数
...
...
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