google-drive-mock 1.1.3 → 1.1.5

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/README.md CHANGED
@@ -5,7 +5,8 @@
5
5
 
6
6
  <p style="text-align: center;">
7
7
  Mock-Server that simulates being google-drive.<br />
8
- Used for testing the <a href="https://rxdb.info/" target="_blank">RxDB Google-Drive-Sync</a>.<br />
8
+ Used for testing the <a href="https://rxdb.info/replication-google-drive.html" target="_blank">RxDB Google-Drive-Sync</a>.<br />
9
+ Sister project to <a href="https://github.com/pubkey/microsoft-onedrive-mock" target="_blank">microsoft-onedrive-mock</a>.<br />
9
10
  Mostly Vibe-Coded.<br />
10
11
  </p>
11
12
 
package/dist/routes/v2.js CHANGED
@@ -22,7 +22,7 @@ const createV2Router = (config) => {
22
22
  const count = parseInt(req.query.maxResults) || 10;
23
23
  const ids = [];
24
24
  for (let i = 0; i < count; i++) {
25
- ids.push(Math.random().toString(36).substring(2, 15));
25
+ ids.push((0, store_1.generateDriveFileId)());
26
26
  }
27
27
  res.json({
28
28
  kind: "drive#generatedIds",
package/dist/store.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Generates a file ID that looks like a real Google Drive file ID.
3
+ * Real IDs are ~28-44 characters using base64url-safe characters (A-Z, a-z, 0-9, -, _).
4
+ */
5
+ export declare function generateDriveFileId(): string;
1
6
  export interface DriveFile {
2
7
  id: string;
3
8
  name: string;
package/dist/store.js CHANGED
@@ -34,7 +34,15 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.driveStore = exports.DriveStore = void 0;
37
+ exports.generateDriveFileId = generateDriveFileId;
37
38
  const crypto = __importStar(require("crypto"));
39
+ /**
40
+ * Generates a file ID that looks like a real Google Drive file ID.
41
+ * Real IDs are ~28-44 characters using base64url-safe characters (A-Z, a-z, 0-9, -, _).
42
+ */
43
+ function generateDriveFileId() {
44
+ return crypto.randomBytes(24).toString('base64url');
45
+ }
38
46
  class DriveStore {
39
47
  constructor() {
40
48
  this.files = new Map();
@@ -63,7 +71,7 @@ class DriveStore {
63
71
  if (!file.name) {
64
72
  throw new Error("File name is required");
65
73
  }
66
- const id = file.id || Math.random().toString(36).substring(7);
74
+ const id = file.id || generateDriveFileId();
67
75
  const now = new Date().toISOString();
68
76
  const stats = this.calculateStats(file.content);
69
77
  const newFile = Object.assign(Object.assign({ kind: "drive#file", mimeType: "application/octet-stream", trashed: false, createdTime: now, modifiedTime: now }, file), { id, version: 1, etag: "1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "google-drive-mock",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Mock-Server that simulates being google-drive. Used for testing.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/routes/v2.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import express, { Request, Response } from 'express';
2
- import { driveStore } from '../store';
2
+ import { driveStore, generateDriveFileId } from '../store';
3
3
  import { toV2File, fromV2Update } from '../mappers';
4
4
  import { AppConfig } from '../types';
5
5
 
@@ -28,7 +28,7 @@ export const createV2Router = (config: AppConfig) => {
28
28
  const count = parseInt(req.query.maxResults as string) || 10;
29
29
  const ids = [];
30
30
  for (let i = 0; i < count; i++) {
31
- ids.push(Math.random().toString(36).substring(2, 15));
31
+ ids.push(generateDriveFileId());
32
32
  }
33
33
  res.json({
34
34
  kind: "drive#generatedIds",
package/src/store.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  import * as crypto from 'crypto';
2
2
 
3
+ /**
4
+ * Generates a file ID that looks like a real Google Drive file ID.
5
+ * Real IDs are ~28-44 characters using base64url-safe characters (A-Z, a-z, 0-9, -, _).
6
+ */
7
+ export function generateDriveFileId(): string {
8
+ return crypto.randomBytes(24).toString('base64url');
9
+ }
10
+
3
11
  export interface DriveFile {
4
12
  id: string;
5
13
  name: string;
@@ -72,7 +80,7 @@ export class DriveStore {
72
80
  if (!file.name) {
73
81
  throw new Error("File name is required");
74
82
  }
75
- const id = file.id || Math.random().toString(36).substring(7);
83
+ const id = file.id || generateDriveFileId();
76
84
  const now = new Date().toISOString();
77
85
 
78
86
  const stats = this.calculateStats(file.content);