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
bddd5725
Commit
bddd5725
authored
Nov 20, 2024
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add function
parent
d33273f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
29 deletions
+35
-29
index.ts
supabase/functions/update-app/index.ts
+30
-28
index.ts
supabase/functions/update-rank/index.ts
+5
-1
No files found.
supabase/functions/update-app/index.ts
View file @
bddd5725
...
...
@@ -6,6 +6,34 @@
import
"
jsr:@supabase/functions-js/edge-runtime.d.ts
"
import
{
createClient
}
from
'
jsr:@supabase/supabase-js@2
'
// 分页查询函数
async
function
fetchAllData
(
supabase
,
table
:
string
,
pageSize
:
number
=
1000
)
{
let
allData
:
any
[]
=
[];
let
offset
=
0
;
while
(
true
)
{
const
{
data
,
error
}
=
await
supabase
.
from
(
table
)
.
select
(
'
*
'
)
// 可以根据需要调整字段
.
order
(
'
created_at
'
,
{
ascending
:
true
})
// 按照创建时间排序
.
range
(
offset
,
offset
+
pageSize
-
1
);
// 分页范围
if
(
error
)
{
console
.
error
(
`Error fetching data from
${
table
}
:`
,
error
);
throw
error
;
}
if
(
data
&&
data
.
length
>
0
)
{
allData
=
allData
.
concat
(
data
);
// 合并当前页数据
offset
+=
pageSize
;
// 移动到下一页
}
else
{
break
;
// 如果没有更多数据,则退出循环
}
}
return
allData
;
}
Deno
.
serve
(
async
(
req
)
=>
{
try
{
// const { name } = await req.json()
...
...
@@ -16,14 +44,14 @@ Deno.serve(async (req) => {
)
// 获取所有 app 数据
const
allApps
=
await
fetchAllData
(
'
app
'
);
const
allApps
=
await
fetchAllData
(
supabase
,
'
app
'
);
// 获取当前时间的整点时间戳
const
timestamp
=
Math
.
floor
(
Date
.
now
()
/
3600000
)
*
3600
;
// 上传所有 app 数据到 storage
const
allAppsJson
=
JSON
.
stringify
(
allApps
);
const
allAppsFileName
=
`app_all_
${
timestamp
}
.json`
;
const
bucketName
=
'
your-bucket-nam
e
'
;
// 替换为存储桶名称
const
bucketName
=
'
cach
e
'
;
// 替换为存储桶名称
const
{
error
:
allAppsUploadError
}
=
await
supabase
.
storage
.
from
(
bucketName
)
...
...
@@ -90,33 +118,7 @@ Deno.serve(async (req) => {
})
// 分页查询函数
async
function
fetchAllData
(
table
:
string
,
pageSize
:
number
=
1000
)
{
let
allData
:
any
[]
=
[];
let
offset
=
0
;
while
(
true
)
{
const
{
data
,
error
}
=
await
supabase
.
from
(
table
)
.
select
(
'
*
'
)
// 可以根据需要调整字段
.
order
(
'
created_at
'
,
{
ascending
:
true
})
// 按照创建时间排序
.
range
(
offset
,
offset
+
pageSize
-
1
);
// 分页范围
if
(
error
)
{
console
.
error
(
`Error fetching data from
${
table
}
:`
,
error
);
throw
error
;
}
if
(
data
&&
data
.
length
>
0
)
{
allData
=
allData
.
concat
(
data
);
// 合并当前页数据
offset
+=
pageSize
;
// 移动到下一页
}
else
{
break
;
// 如果没有更多数据,则退出循环
}
}
return
allData
;
}
/* To invoke locally:
...
...
supabase/functions/update-rank/index.ts
View file @
bddd5725
...
...
@@ -42,7 +42,11 @@ Deno.serve(async (req) => {
return
new
Response
(
JSON
.
stringify
({
error
:
'
Failed to upload file
'
}),
{
status
:
500
});
}
return
new
Response
(
JSON
.
stringify
({
data
}),
{
return
new
Response
(
JSON
.
stringify
({
code
:
200
,
data
:
null
,
message
:
'
success
'
}),
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
status
:
200
,
})
...
...
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