Skip to content

Commit 02f98c2

Browse files
authored
Merge pull request #19 from scrapeless-ai/feat/local_dev
Local dev
2 parents 238516e + 65d4512 commit 02f98c2

File tree

23 files changed

+5826
-3785
lines changed

23 files changed

+5826
-3785
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ SCRAPELESS_LOG_MAX_SIZE=100m
2424
SCRAPELESS_LOG_MAX_BACKUPS=5
2525
SCRAPELESS_LOG_MAX_AGE=7
2626
SCRAPELESS_LOG_ROOT_DIR=./logs
27+
SCRAPELESS_IS_ONLINE=false

.gitignore

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
# 依赖目录
21
node_modules/
32
yarn-error.log
43
npm-debug.log
54

6-
# 构建输出
75
dist/
86
build/
97
lib/
8+
storage/*
9+
10+
!storage/http/
11+
!storage/memory/
1012

11-
# IDE 文件
1213
.vscode/
1314
.idea/
1415
*.sublime-project
1516
*.sublime-workspace
1617

17-
# 操作系统文件
1818
.DS_Store
1919
Thumbs.db
2020

21-
# 环境变量
2221
.env
2322
.env.local
2423
.env.*.local
2524
.env.prod
2625

27-
# 测试覆盖率
2826
coverage/
2927
.nyc_output/
3028

31-
# 临时文件
3229
tmp/
3330
temp/
3431
*.log

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default {
2727
'revert',
2828
'style',
2929
'test',
30+
'wip'
3031
],
3132
],
3233
},

examples/storage-example.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ async function datasetExample(client) {
1616
console.log(`Dataset created with ID: ${dataset.id}`);
1717

1818
// Add items to the dataset
19-
await client.storage.dataset.addItems([
19+
await client.storage.dataset.addItems(dataset.id, [
2020
{ name: 'Product 1', price: 19.99, category: 'Electronics' },
2121
{ name: 'Product 2', price: 29.99, category: 'Home' },
2222
{ name: 'Product 3', price: 9.99, category: 'Clothing' }
2323
]);
2424
console.log('Items added to dataset');
2525

2626
// Get items from the dataset
27-
const items = await client.storage.dataset.getItems({
27+
const items = await client.storage.dataset.getItems(dataset.id, {
2828
page: 1,
2929
pageSize: 10
3030
});
@@ -48,7 +48,7 @@ async function kvStorageExample(client) {
4848
console.log(`KV namespace created with ID: ${namespace.id}`);
4949

5050
// Set values in the namespace
51-
await client.storage.kv.setValue({
51+
await client.storage.kv.setValue(namespace.id, {
5252
key: 'appConfig',
5353
value: JSON.stringify({
5454
apiVersion: '1.0',
@@ -61,11 +61,11 @@ async function kvStorageExample(client) {
6161
console.log('Value set in KV store');
6262

6363
// Get value from the namespace
64-
const config = await client.storage.kv.getValue('appConfig');
64+
const config = await client.storage.kv.getValue(namespace.id, 'appConfig');
6565
console.log('Retrieved config:', JSON.parse(config));
6666

6767
// List keys in the namespace
68-
const keys = await client.storage.kv.listKeys({ page: 1, pageSize: 10 });
68+
const keys = await client.storage.kv.listKeys(namespace.id, { page: 1, pageSize: 10 });
6969
console.log('KV store keys:', keys);
7070

7171
console.log('KV storage example completed\n');
@@ -89,13 +89,13 @@ async function objectStorageExample(client) {
8989
console.log(`Object bucket created with ID: ${bucket.id}`);
9090

9191
// Upload a file to the bucket (in a real scenario, you would use a real file path)
92-
const uploadResult = await client.storage.object.put({
92+
const uploadResult = await client.storage.object.put(bucket.id, {
9393
file: 'example/sample-image.jpg'
9494
});
9595
console.log('File uploaded to object storage:', uploadResult);
9696

9797
// List objects in the bucket
98-
const objects = await client.storage.object.list({ page: 1, pageSize: 10 });
98+
const objects = await client.storage.object.list(bucket.id, { page: 1, pageSize: 10 });
9999
console.log('Objects in bucket:', objects);
100100

101101
console.log('Object storage example completed\n');
@@ -119,7 +119,7 @@ async function queueStorageExample(client) {
119119
console.log(`Queue created with ID: ${queue.id}`);
120120

121121
// Push messages to the queue
122-
const message1 = await client.storage.queue.push({
122+
const message1 = await client.storage.queue.push(queue.id, {
123123
name: 'processImage',
124124
payload: JSON.stringify({
125125
imageId: '123',
@@ -131,7 +131,7 @@ async function queueStorageExample(client) {
131131
});
132132
console.log('Message pushed to queue:', message1);
133133

134-
const message2 = await client.storage.queue.push({
134+
const message2 = await client.storage.queue.push(queue.id, {
135135
name: 'generateReport',
136136
payload: JSON.stringify({ reportType: 'monthly', format: 'pdf' }),
137137
retry: 2,
@@ -141,12 +141,12 @@ async function queueStorageExample(client) {
141141
console.log('Message pushed to queue:', message2);
142142

143143
// Pull messages from the queue
144-
const messages = await client.storage.queue.pull();
144+
const messages = await client.storage.queue.pull(queue.id);
145145
console.log('Messages pulled from queue:', messages);
146146

147147
// Acknowledge a message (if any)
148148
if (messages && messages.length > 0) {
149-
await client.storage.queue.ack(messages[0].id);
149+
await client.storage.queue.ack(queue.id, messages[0].id);
150150
console.log(`Message ${messages[0].id} acknowledged`);
151151
}
152152

@@ -169,7 +169,7 @@ async function runExample() {
169169
// Run the examples
170170
await datasetExample(client);
171171
await kvStorageExample(client);
172-
await objectStorageExample(client);
172+
// await objectStorageExample(client);
173173
await queueStorageExample(client);
174174

175175
console.log('All storage examples completed successfully');

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"puppeteer-core": "^24.9.0",
5353
"stack-trace": "1.0.0-pre2",
5454
"tsdown": "^0.11.13",
55+
"uuid": "^11.1.0",
5556
"winston": "^3.17.0",
5657
"winston-daily-rotate-file": "^5.0.0",
5758
"winston-transport": "^4.9.0",

0 commit comments

Comments
 (0)