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
ab261170
Commit
ab261170
authored
Dec 18, 2024
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cache annoument and fix crwal data and fix cache app filed
parent
50de159f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
32 deletions
+89
-32
cli-latest
supabase/.temp/cli-latest
+1
-1
index.ts
supabase/functions/crawl-data/index.ts
+5
-0
index.ts
supabase/functions/update-app-recommend/index.ts
+29
-11
index.ts
supabase/functions/update-app/index.ts
+54
-20
No files found.
supabase/.temp/cli-latest
View file @
ab261170
v2.0.0
v2.1.1
\ No newline at end of file
\ No newline at end of file
supabase/functions/crawl-data/index.ts
View file @
ab261170
...
@@ -277,6 +277,11 @@ async function getTonAppInfo(supabase) {
...
@@ -277,6 +277,11 @@ async function getTonAppInfo(supabase) {
...
cleanedApp
,
...
cleanedApp
,
category_id
:
categoryInfo
.
id
category_id
:
categoryInfo
.
id
};
};
if
(
!
insertApp
.
appPlatforms
&&
!
insertApp
.
description
&&
!
insertApp
.
images
&&
insertApp
.
images
==
[]
&&
(
!
insertApp
.
link
||
insertApp
.
link
==
"
https://
"
))
{
continue
}
else
if
(
!
insertApp
.
appPlatforms
&&
!
insertApp
.
description
&&
(
!
insertApp
.
images
||
insertApp
.
images
==
[]))
{
insertApp
.
is_forward
=
true
}
console
.
log
(
"
insert app name
"
,
insertApp
.
name
);
console
.
log
(
"
insert app name
"
,
insertApp
.
name
);
appsToInsert
.
push
(
insertApp
);
appsToInsert
.
push
(
insertApp
);
}
}
...
...
supabase/functions/update-app-recommend/index.ts
View file @
ab261170
...
@@ -14,7 +14,7 @@ async function fetchAllData(supabase, table: string, pageSize: number = 1000) {
...
@@ -14,7 +14,7 @@ async function fetchAllData(supabase, table: string, pageSize: number = 1000) {
while
(
true
)
{
while
(
true
)
{
const
{
data
,
error
}
=
await
supabase
const
{
data
,
error
}
=
await
supabase
.
from
(
table
)
.
from
(
table
)
.
select
(
'
id,name,icon,
description,points,category_id,link,images,appPlatforms,caption,is_forward,is_show
,recommend,category(is_show)
'
)
// 可以根据需要调整字段
.
select
(
'
id,name,icon,
points,link,appPlatforms,caption,category_id,is_forward
,recommend,category(is_show)
'
)
// 可以根据需要调整字段
.
gt
(
'
is_show
'
,
0
)
.
gt
(
'
is_show
'
,
0
)
.
gt
(
'
recommend
'
,
0
)
.
gt
(
'
recommend
'
,
0
)
// .eq('is_show', 1)
// .eq('is_show', 1)
...
@@ -93,6 +93,32 @@ async function cacheTaskCount(supabase, directory, bucketName) {
...
@@ -93,6 +93,32 @@ async function cacheTaskCount(supabase, directory, bucketName) {
}
}
}
}
async
function
cacheAnnouncementData
(
supabase
,
directory
,
bucketName
)
{
const
pageFileName
=
`
${
directory
}
/announcement_data.json`
;
let
{
data
:
announcementData
,
error
:
announcementError
}
=
await
supabase
.
from
(
"
announcement
"
)
.
select
(
"
comment
"
)
.
is
(
'
deleted_at
'
,
null
)
.
order
(
"
update_at
"
,
{
ascending
:
false
})
.
limit
(
0
,
1
);
const
pageJson
=
JSON
.
stringify
(
announcementData
);
const
{
error
:
pageUploadError
}
=
await
supabase
.
storage
.
from
(
bucketName
)
.
upload
(
pageFileName
,
new
Blob
([
pageJson
]),
{
contentType
:
'
application/json
'
,
upsert
:
true
,
});
if
(
pageUploadError
)
{
console
.
error
(
`Error uploading announcement_data JSON:`
,
pageUploadError
);
}
else
{
console
.
log
(
`Uploading announcement_data JSON scuccessful`
);
}
}
async
function
cacheRecommendApp
(
supabase
,
allApps
,
directory
,
bucketName
)
{
async
function
cacheRecommendApp
(
supabase
,
allApps
,
directory
,
bucketName
)
{
const
recommendPageSize
=
3
;
const
recommendPageSize
=
3
;
// const recommendApps = allApps.filter(app => app.recommend > 0)
// const recommendApps = allApps.filter(app => app.recommend > 0)
...
@@ -163,17 +189,9 @@ Deno.serve(async (req) => {
...
@@ -163,17 +189,9 @@ Deno.serve(async (req) => {
EdgeRuntime
.
waitUntil
(
cacheTaskCount
(
supabase
,
directory
,
bucketName
));
EdgeRuntime
.
waitUntil
(
cacheTaskCount
(
supabase
,
directory
,
bucketName
));
EdgeRuntime
.
waitUntil
(
cacheRecommendApp
(
supabase
,
allApps
,
directory
,
bucketName
));
EdgeRuntime
.
waitUntil
(
cacheAnnouncementData
(
supabase
,
directory
,
bucketName
));
// (async () => {
// try {
// await cacheTaskCount(supabase, directory, bucketName)
// await cacheRecommendApp(supabase, allApps, directory, bucketName)
EdgeRuntime
.
waitUntil
(
cacheRecommendApp
(
supabase
,
allApps
,
directory
,
bucketName
));
// } catch (error) {
// console.error('Background crawl error:', error)
// }
// })()
return
new
Response
(
return
new
Response
(
JSON
.
stringify
({
JSON
.
stringify
({
...
...
supabase/functions/update-app/index.ts
View file @
ab261170
...
@@ -14,7 +14,7 @@ async function fetchAllData(supabase, table: string, pageSize: number = 1000) {
...
@@ -14,7 +14,7 @@ async function fetchAllData(supabase, table: string, pageSize: number = 1000) {
while
(
true
)
{
while
(
true
)
{
const
{
data
,
error
}
=
await
supabase
const
{
data
,
error
}
=
await
supabase
.
from
(
table
)
.
from
(
table
)
.
select
(
'
id,name,icon,
description,points,category_id,link,images,appPlatforms,caption,is_forward,is_show
,category(is_show)
'
)
// 可以根据需要调整字段
.
select
(
'
id,name,icon,
points,link,appPlatforms,caption,category_id,is_forward
,category(is_show)
'
)
// 可以根据需要调整字段
.
gt
(
'
is_show
'
,
0
)
.
gt
(
'
is_show
'
,
0
)
// .eq('is_show', 1)
// .eq('is_show', 1)
.
eq
(
"
category.is_show
"
,
true
)
.
eq
(
"
category.is_show
"
,
true
)
...
@@ -97,6 +97,12 @@ async function cacheAllApp(supabase) {
...
@@ -97,6 +97,12 @@ async function cacheAllApp(supabase) {
}
}
async
function
cacheCategoryApp
(
supabase
,
allApps
,
directory
,
bucketName
)
{
async
function
cacheCategoryApp
(
supabase
,
allApps
,
directory
,
bucketName
)
{
let
categoryInfo
=
{
app_all
:
{
title
:
"
ALL
"
,
count
:
allApps
.
length
,
}
}
let
categoryCount
=
{
let
categoryCount
=
{
app_all
:
allApps
.
length
,
app_all
:
allApps
.
length
,
}
}
...
@@ -108,17 +114,27 @@ async function cacheCategoryApp(supabase, allApps, directory, bucketName) {
...
@@ -108,17 +114,27 @@ async function cacheCategoryApp(supabase, allApps, directory, bucketName) {
}
}
groupedData
[
app
.
category_id
].
push
(
app
);
groupedData
[
app
.
category_id
].
push
(
app
);
});
});
const
{
data
:
categoryData
,
error
}
=
await
supabase
.
from
(
'
category
'
).
select
(
'
id,title
'
).
eq
(
'
is_show
'
,
true
)
const
categoryMap
=
new
Map
(
categoryData
?.
map
(
category
=>
[
category
.
id
,
category
.
title
]));
console
.
log
(
"
categoryMap
"
);
if
(
error
)
{
console
.
error
(
"
getCategoryInfo error:
"
,
error
);
}
// 上传每个 category_id 的分页数据
// 上传每个 category_id 的分页数据
for
(
const
[
categoryId
,
apps
]
of
Object
.
entries
(
groupedData
))
{
for
(
const
[
categoryId
,
apps
]
of
Object
.
entries
(
groupedData
))
{
console
.
log
(
"
categoryId:
"
,
categoryId
);
const
totalCount
=
apps
.
length
;
// 当前分类的总数
const
totalCount
=
apps
.
length
;
// 当前分类的总数
categoryCount
[
categoryId
]
=
totalCount
//缓存每个分类的app数据
const
pageSize
=
30
;
const
pageSize
=
30
;
const
paginatedApps
=
[];
const
paginatedApps
=
[];
for
(
let
i
=
0
;
i
<
totalCount
;
i
+=
pageSize
)
{
for
(
let
i
=
0
;
i
<
totalCount
;
i
+=
pageSize
)
{
paginatedApps
.
push
(
apps
.
slice
(
i
,
i
+
pageSize
));
paginatedApps
.
push
(
apps
.
slice
(
i
,
i
+
pageSize
));
}
}
categoryInfo
[
categoryId
]
=
{
title
:
categoryMap
.
get
(
categoryId
),
count
:
totalCount
}
categoryCount
[
categoryId
]
=
totalCount
// 遍历分页数据并上传
// 遍历分页数据并上传
for
(
let
pageNum
=
1
;
pageNum
<=
paginatedApps
.
length
;
pageNum
++
)
{
for
(
let
pageNum
=
1
;
pageNum
<=
paginatedApps
.
length
;
pageNum
++
)
{
const
pageApps
=
paginatedApps
[
pageNum
-
1
];
const
pageApps
=
paginatedApps
[
pageNum
-
1
];
...
@@ -146,24 +162,42 @@ async function cacheCategoryApp(supabase, allApps, directory, bucketName) {
...
@@ -146,24 +162,42 @@ async function cacheCategoryApp(supabase, allApps, directory, bucketName) {
console
.
log
(
`Uploading page
${
categoryId
}
_
${
pageNum
}
.json JSON successful`
);
console
.
log
(
`Uploading page
${
categoryId
}
_
${
pageNum
}
.json JSON successful`
);
}
}
}
}
}
const
categoryCountFileName
=
`
${
directory
}
/category_count.json`
;
// 缓存分类信息的数据
const
categoryCountJson
=
JSON
.
stringify
(
categoryCount
);
const
categoryInfoFileName
=
`
${
directory
}
/category_Info.json`
;
const
categoryInfoJson
=
JSON
.
stringify
(
categoryInfo
);
const
{
error
:
categoryInfoUploadError
}
=
await
supabase
.
storage
.
from
(
bucketName
)
.
upload
(
categoryInfoFileName
,
new
Blob
([
categoryInfoJson
]),
{
contentType
:
'
application/json
'
,
upsert
:
true
,
});
if
(
categoryInfoUploadError
)
{
console
.
error
(
`Error uploading category_info JSON:`
,
categoryInfoUploadError
);
}
else
{
console
.
log
(
`Uploading page category_info JSON successful`
);
}
const
{
error
:
categoryCountUploadError
}
=
await
supabase
.
storage
// 缓存分类数量的数据
.
from
(
bucketName
)
const
categoryCountFileName
=
`
${
directory
}
/category_count.json`
;
.
upload
(
categoryCountFileName
,
new
Blob
([
categoryCountJson
]),
{
const
categoryCountJson
=
JSON
.
stringify
(
categoryCount
);
contentType
:
'
application/json
'
,
const
{
error
:
categoryCountUploadError
}
=
await
supabase
.
storage
upsert
:
true
,
.
from
(
bucketName
)
});
.
upload
(
categoryCountFileName
,
new
Blob
([
categoryCountJson
]),
{
if
(
categoryCountUploadError
)
{
contentType
:
'
application/json
'
,
console
.
error
(
upsert
:
true
,
`Error uploading category_count JSON:`
,
});
categoryCountUploadError
if
(
categoryCountUploadError
)
{
);
console
.
error
(
}
else
{
`Error uploading category_count JSON:`
,
console
.
log
(
`Uploading page category_count JSON successful`
);
categoryCountUploadError
}
);
}
else
{
console
.
log
(
`Uploading page category_count JSON successful`
);
}
}
}
}
...
...
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