codequiry 1.0.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +123 -100
- package/index.js +251 -126
- package/package.json +36 -35
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Codequiry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,100 +1,123 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```javascript
|
|
50
|
-
Codequiry
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
1
|
+
# Codequiry - Node.js SDK
|
|
2
|
+
|
|
3
|
+
Official Node.js SDK for [Codequiry's](https://codequiry.com) Code Plagiarism & Similarity Detection API.
|
|
4
|
+
|
|
5
|
+
Check source code files against billions of web sources, public repositories, and peer submissions. Supports 65+ programming languages.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install codequiry
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
const Codequiry = require('codequiry');
|
|
17
|
+
|
|
18
|
+
const cq = new Codequiry('YOUR_API_KEY');
|
|
19
|
+
|
|
20
|
+
// Create a check, upload files, start, and get results
|
|
21
|
+
async function run() {
|
|
22
|
+
// Create a check (language 14 = Python)
|
|
23
|
+
const check = await cq.createCheck('Assignment 1', 14);
|
|
24
|
+
console.log('Created:', check);
|
|
25
|
+
|
|
26
|
+
// Upload a zip file
|
|
27
|
+
await cq.uploadFile(check.check.id, './submissions.zip');
|
|
28
|
+
|
|
29
|
+
// Start the check
|
|
30
|
+
await cq.startCheck(check.check.id, { dbcheck: true });
|
|
31
|
+
|
|
32
|
+
// Poll until complete
|
|
33
|
+
const status = await cq.pollUntilComplete(check.check.id, {
|
|
34
|
+
onProgress: (s) => console.log('Progress:', s),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Get results
|
|
38
|
+
const overview = await cq.getOverview(check.check.id);
|
|
39
|
+
console.log('Results:', overview);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
run().catch(console.error);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## API Reference
|
|
46
|
+
|
|
47
|
+
### Constructor
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
const cq = new Codequiry('YOUR_API_KEY');
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Account
|
|
54
|
+
|
|
55
|
+
| Method | Description |
|
|
56
|
+
|--------|-------------|
|
|
57
|
+
| `cq.account()` | Get account info and usage quota |
|
|
58
|
+
|
|
59
|
+
### Checks
|
|
60
|
+
|
|
61
|
+
| Method | Description |
|
|
62
|
+
|--------|-------------|
|
|
63
|
+
| `cq.checks()` | List all checks |
|
|
64
|
+
| `cq.createCheck(name, languageId, testType?)` | Create a new check |
|
|
65
|
+
| `cq.getCheck(checkId)` | Get check info and status |
|
|
66
|
+
| `cq.deleteCheck(checkId)` | Delete a check |
|
|
67
|
+
|
|
68
|
+
### Upload
|
|
69
|
+
|
|
70
|
+
| Method | Description |
|
|
71
|
+
|--------|-------------|
|
|
72
|
+
| `cq.uploadFile(checkId, filePath)` | Upload a ZIP file |
|
|
73
|
+
| `cq.uploadBatch(checkId, filePaths)` | Upload multiple ZIP files |
|
|
74
|
+
|
|
75
|
+
### Start & Status
|
|
76
|
+
|
|
77
|
+
| Method | Description |
|
|
78
|
+
|--------|-------------|
|
|
79
|
+
| `cq.startCheck(checkId, options?)` | Start a check. Options: `{ dbcheck, webcheck, testType }` |
|
|
80
|
+
| `cq.getStatus(checkId)` | Get current check status |
|
|
81
|
+
| `cq.pollUntilComplete(checkId, options?)` | Poll until done. Options: `{ interval, timeout, onProgress }` |
|
|
82
|
+
|
|
83
|
+
### Results
|
|
84
|
+
|
|
85
|
+
| Method | Description |
|
|
86
|
+
|--------|-------------|
|
|
87
|
+
| `cq.getOverview(checkId)` | Results overview with similarity scores |
|
|
88
|
+
| `cq.getResults(checkId, submissionId)` | Detailed results for a submission |
|
|
89
|
+
| `cq.getSummary(checkId)` | Summary statistics |
|
|
90
|
+
|
|
91
|
+
### Reference Data
|
|
92
|
+
|
|
93
|
+
| Method | Description |
|
|
94
|
+
|--------|-------------|
|
|
95
|
+
| `cq.getLanguages()` | List supported programming languages |
|
|
96
|
+
| `cq.getTestTypes()` | List available check engine types |
|
|
97
|
+
|
|
98
|
+
## Supported Languages
|
|
99
|
+
|
|
100
|
+
Java, Python, C, C++, C#, Perl, PHP, SQL, VB, XML, Haskell, Pascal, Go, Matlab, Lisp, Ruby, Assembly, HTML, JavaScript/TypeScript, Swift, Kotlin, Dart, Elixir, Jupyter Notebooks, and many more.
|
|
101
|
+
|
|
102
|
+
## Migration from v1
|
|
103
|
+
|
|
104
|
+
v2 uses modern async/await instead of callbacks:
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
// v1 (old)
|
|
108
|
+
Codequiry.setAPIKey('key');
|
|
109
|
+
Codequiry.checks(function(data, err) {
|
|
110
|
+
console.log(data);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// v2 (new)
|
|
114
|
+
const cq = new Codequiry('key');
|
|
115
|
+
const checks = await cq.checks();
|
|
116
|
+
console.log(checks);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Links
|
|
120
|
+
|
|
121
|
+
- [Codequiry](https://codequiry.com)
|
|
122
|
+
- [API Documentation](https://codequiry.com/usage/docs)
|
|
123
|
+
- [CLI Tool](https://www.npmjs.com/package/codequiry-cli)
|
package/index.js
CHANGED
|
@@ -1,126 +1,251 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const axios = require('axios');
|
|
4
|
+
const FormData = require('form-data');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const BASE_URL = 'https://codequiry.com/api/v1';
|
|
8
|
+
|
|
9
|
+
class Codequiry {
|
|
10
|
+
/**
|
|
11
|
+
* Create a Codequiry SDK instance.
|
|
12
|
+
* @param {string} apiKey - Your Codequiry API key
|
|
13
|
+
*/
|
|
14
|
+
constructor(apiKey) {
|
|
15
|
+
if (!apiKey) {
|
|
16
|
+
throw new Error('API key is required. Get one at https://codequiry.com/dashboard');
|
|
17
|
+
}
|
|
18
|
+
this.apiKey = apiKey;
|
|
19
|
+
this.client = axios.create({
|
|
20
|
+
baseURL: BASE_URL,
|
|
21
|
+
headers: {
|
|
22
|
+
apikey: apiKey,
|
|
23
|
+
Accept: 'application/json',
|
|
24
|
+
},
|
|
25
|
+
timeout: 120000,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// ─── Account ──────────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get account information and usage quota.
|
|
33
|
+
* @returns {Promise<Object>}
|
|
34
|
+
*/
|
|
35
|
+
async account() {
|
|
36
|
+
const res = await this.client.get('/account');
|
|
37
|
+
return res.data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ─── Checks ───────────────────────────────────────────
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* List all checks.
|
|
44
|
+
* @returns {Promise<Object>}
|
|
45
|
+
*/
|
|
46
|
+
async checks() {
|
|
47
|
+
const res = await this.client.get('/checks');
|
|
48
|
+
return res.data;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Create a new check.
|
|
53
|
+
* @param {string} name - Check name
|
|
54
|
+
* @param {number} language - Language ID (get from getLanguages())
|
|
55
|
+
* @param {number} [testType] - Test type ID (get from getTestTypes())
|
|
56
|
+
* @returns {Promise<Object>}
|
|
57
|
+
*/
|
|
58
|
+
async createCheck(name, language, testType) {
|
|
59
|
+
const body = { name, language };
|
|
60
|
+
if (testType) body.test_type = testType;
|
|
61
|
+
const res = await this.client.post('/check/create', body);
|
|
62
|
+
return res.data;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get check information and status.
|
|
67
|
+
* @param {number} checkId
|
|
68
|
+
* @returns {Promise<Object>}
|
|
69
|
+
*/
|
|
70
|
+
async getCheck(checkId) {
|
|
71
|
+
const res = await this.client.post('/check/get', { check_id: checkId });
|
|
72
|
+
return res.data;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Delete a check.
|
|
77
|
+
* @param {number} checkId
|
|
78
|
+
* @returns {Promise<Object>}
|
|
79
|
+
*/
|
|
80
|
+
async deleteCheck(checkId) {
|
|
81
|
+
const res = await this.client.delete(`/checks/${checkId}`);
|
|
82
|
+
return res.data;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ─── Upload ───────────────────────────────────────────
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Upload a ZIP file to a check.
|
|
89
|
+
* @param {number} checkId
|
|
90
|
+
* @param {string} filePath - Path to a .zip file
|
|
91
|
+
* @returns {Promise<Object>}
|
|
92
|
+
*/
|
|
93
|
+
async uploadFile(checkId, filePath) {
|
|
94
|
+
const form = new FormData();
|
|
95
|
+
form.append('check_id', String(checkId));
|
|
96
|
+
form.append('file', fs.createReadStream(filePath));
|
|
97
|
+
const res = await this.client.post('/check/upload', form, {
|
|
98
|
+
headers: form.getHeaders(),
|
|
99
|
+
maxContentLength: Infinity,
|
|
100
|
+
maxBodyLength: Infinity,
|
|
101
|
+
});
|
|
102
|
+
return res.data;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Upload multiple ZIP files to a check (batch).
|
|
107
|
+
* @param {number} checkId
|
|
108
|
+
* @param {string[]} filePaths - Array of paths to .zip files
|
|
109
|
+
* @returns {Promise<Object>}
|
|
110
|
+
*/
|
|
111
|
+
async uploadBatch(checkId, filePaths) {
|
|
112
|
+
const form = new FormData();
|
|
113
|
+
form.append('check_id', String(checkId));
|
|
114
|
+
filePaths.forEach((fp) => {
|
|
115
|
+
form.append('files[]', fs.createReadStream(fp));
|
|
116
|
+
});
|
|
117
|
+
const res = await this.client.post('/check/upload-batch', form, {
|
|
118
|
+
headers: form.getHeaders(),
|
|
119
|
+
maxContentLength: Infinity,
|
|
120
|
+
maxBodyLength: Infinity,
|
|
121
|
+
});
|
|
122
|
+
return res.data;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ─── Start & Status ───────────────────────────────────
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Start a check.
|
|
129
|
+
* @param {number} checkId
|
|
130
|
+
* @param {Object} [options]
|
|
131
|
+
* @param {boolean} [options.dbcheck=false] - Enable database check
|
|
132
|
+
* @param {boolean} [options.webcheck=false] - Enable web check
|
|
133
|
+
* @param {number} [options.testType] - Test type override
|
|
134
|
+
* @returns {Promise<Object>}
|
|
135
|
+
*/
|
|
136
|
+
async startCheck(checkId, options = {}) {
|
|
137
|
+
const body = {
|
|
138
|
+
check_id: checkId,
|
|
139
|
+
dbcheck: options.dbcheck ? 1 : 0,
|
|
140
|
+
webcheck: options.webcheck ? 1 : 0,
|
|
141
|
+
};
|
|
142
|
+
if (options.testType) body.test_type = options.testType;
|
|
143
|
+
const res = await this.client.post('/check/start', body);
|
|
144
|
+
return res.data;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Get check status (for polling).
|
|
149
|
+
* @param {number} checkId
|
|
150
|
+
* @returns {Promise<Object>}
|
|
151
|
+
*/
|
|
152
|
+
async getStatus(checkId) {
|
|
153
|
+
const res = await this.client.get(`/checks/${checkId}/status`);
|
|
154
|
+
return res.data;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ─── Results ──────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Get results overview for a check.
|
|
161
|
+
* @param {number} checkId
|
|
162
|
+
* @returns {Promise<Object>}
|
|
163
|
+
*/
|
|
164
|
+
async getOverview(checkId) {
|
|
165
|
+
const res = await this.client.post('/check/overview', { check_id: checkId });
|
|
166
|
+
return res.data;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Get detailed results for a specific submission.
|
|
171
|
+
* @param {number} checkId
|
|
172
|
+
* @param {number} submissionId
|
|
173
|
+
* @returns {Promise<Object>}
|
|
174
|
+
*/
|
|
175
|
+
async getResults(checkId, submissionId) {
|
|
176
|
+
const res = await this.client.post('/check/results', {
|
|
177
|
+
check_id: checkId,
|
|
178
|
+
submission_id: submissionId,
|
|
179
|
+
});
|
|
180
|
+
return res.data;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Get summary stats for a check.
|
|
185
|
+
* @param {number} checkId
|
|
186
|
+
* @returns {Promise<Object>}
|
|
187
|
+
*/
|
|
188
|
+
async getSummary(checkId) {
|
|
189
|
+
const res = await this.client.get(`/checks/${checkId}/summary`);
|
|
190
|
+
return res.data;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ─── Reference Data ───────────────────────────────────
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Get supported programming languages.
|
|
197
|
+
* @returns {Promise<Object>}
|
|
198
|
+
*/
|
|
199
|
+
async getLanguages() {
|
|
200
|
+
const res = await this.client.get('/languages');
|
|
201
|
+
return res.data;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Get available test/check types.
|
|
206
|
+
* @returns {Promise<Object>}
|
|
207
|
+
*/
|
|
208
|
+
async getTestTypes() {
|
|
209
|
+
const res = await this.client.get('/test-types');
|
|
210
|
+
return res.data;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ─── Helpers ──────────────────────────────────────────
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Poll a check until completion.
|
|
217
|
+
* @param {number} checkId
|
|
218
|
+
* @param {Object} [options]
|
|
219
|
+
* @param {number} [options.interval=3000] - Poll interval in ms
|
|
220
|
+
* @param {number} [options.timeout=600000] - Max wait time in ms
|
|
221
|
+
* @param {function} [options.onProgress] - Callback with status updates
|
|
222
|
+
* @returns {Promise<Object>} Final status
|
|
223
|
+
*/
|
|
224
|
+
async pollUntilComplete(checkId, options = {}) {
|
|
225
|
+
const interval = options.interval || 3000;
|
|
226
|
+
const timeout = options.timeout || 600000;
|
|
227
|
+
const startTime = Date.now();
|
|
228
|
+
|
|
229
|
+
while (Date.now() - startTime < timeout) {
|
|
230
|
+
const status = await this.getStatus(checkId);
|
|
231
|
+
|
|
232
|
+
if (options.onProgress) {
|
|
233
|
+
options.onProgress(status);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const statusVal = status?.status ?? status?.check_status;
|
|
237
|
+
if (statusVal === 5 || statusVal === 'completed' || statusVal === 'done') {
|
|
238
|
+
return status;
|
|
239
|
+
}
|
|
240
|
+
if (statusVal === 'failed' || statusVal === 'error' || statusVal === -1) {
|
|
241
|
+
throw new Error('Check failed: ' + JSON.stringify(status));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
throw new Error('Polling timed out after ' + timeout + 'ms');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
module.exports = Codequiry;
|
package/package.json
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "codequiry",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Node
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/cqchecker/codequiry-sdk.git"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"codequiry",
|
|
15
|
-
"
|
|
16
|
-
"code
|
|
17
|
-
"code
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
],
|
|
23
|
-
"author": "Codequiry",
|
|
24
|
-
"license": "
|
|
25
|
-
"bugs": {
|
|
26
|
-
"url": "https://github.com/cqchecker/codequiry-sdk/issues"
|
|
27
|
-
},
|
|
28
|
-
"homepage": "https://
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"axios": "^
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "codequiry",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Node.js SDK for Codequiry's Code Plagiarism & Similarity Detection API",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"No tests yet\""
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/cqchecker/codequiry-sdk.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"codequiry",
|
|
15
|
+
"plagiarism",
|
|
16
|
+
"code-similarity",
|
|
17
|
+
"code-plagiarism",
|
|
18
|
+
"similarity-detection",
|
|
19
|
+
"moss",
|
|
20
|
+
"api",
|
|
21
|
+
"sdk"
|
|
22
|
+
],
|
|
23
|
+
"author": "Codequiry",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/cqchecker/codequiry-sdk/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://codequiry.com",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"axios": "^1.6.0",
|
|
31
|
+
"form-data": "^4.0.0"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=14.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|