@aspan-corporation/ac-shared 1.2.31 → 1.2.33
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/lib/lambda/index.d.ts +1 -0
- package/lib/services/s3.d.ts +7 -0
- package/lib/services/s3.js +11 -0
- package/lib/utils/diary.d.ts +7 -3
- package/lib/utils/diary.js +33 -10
- package/package.json +1 -1
package/lib/lambda/index.d.ts
CHANGED
package/lib/services/s3.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export declare class S3Service {
|
|
|
19
19
|
listObjectsV2(listObjectsV2CommandInput: ListObjectsV2CommandInput): Promise<import("@aws-sdk/client-s3").ListObjectsV2CommandOutput>;
|
|
20
20
|
getObject(getObjectCommandInput: GetObjectCommandInput): Promise<Buffer>;
|
|
21
21
|
getSignedUrl(getObjectCommandInput: GetObjectCommandInput): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Presigned PUT URL — lets a browser upload a single object directly to S3
|
|
24
|
+
* without the bytes passing through the API/Lambda. Sign without locking a
|
|
25
|
+
* ContentType so the client may send any Content-Type header; the object's
|
|
26
|
+
* extension (not its stored MIME type) drives downstream processing.
|
|
27
|
+
*/
|
|
28
|
+
getSignedUploadUrl(putObjectCommandInput: PutObjectCommandInput, expiresIn?: number): Promise<string>;
|
|
22
29
|
putObject(putObjectCommandInput: PutObjectCommandInput): Promise<PutObjectCommandOutput>;
|
|
23
30
|
headObject(headObjectCommandInput: HeadObjectCommandInput): Promise<import("@aws-sdk/client-s3").HeadObjectCommandOutput>;
|
|
24
31
|
checkIfObjectExists(headObjectCommandInput: HeadObjectCommandInput): Promise<boolean>;
|
package/lib/services/s3.js
CHANGED
|
@@ -60,6 +60,17 @@ export class S3Service {
|
|
|
60
60
|
const signedUrl = await getSignedUrl(this.client, new GetObjectCommand(getObjectCommandInput), { expiresIn: 3600 });
|
|
61
61
|
return signedUrl;
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Presigned PUT URL — lets a browser upload a single object directly to S3
|
|
65
|
+
* without the bytes passing through the API/Lambda. Sign without locking a
|
|
66
|
+
* ContentType so the client may send any Content-Type header; the object's
|
|
67
|
+
* extension (not its stored MIME type) drives downstream processing.
|
|
68
|
+
*/
|
|
69
|
+
async getSignedUploadUrl(putObjectCommandInput, expiresIn = 3600) {
|
|
70
|
+
this.logger.debug("getSignedUploadUrl", { putObjectCommandInput });
|
|
71
|
+
const signedUrl = await getSignedUrl(this.client, new PutObjectCommand(putObjectCommandInput), { expiresIn });
|
|
72
|
+
return signedUrl;
|
|
73
|
+
}
|
|
63
74
|
async putObject(putObjectCommandInput) {
|
|
64
75
|
this.logger.debug("putObject", { putObjectCommandInput });
|
|
65
76
|
return await this.client.send(new PutObjectCommand(putObjectCommandInput));
|
package/lib/utils/diary.d.ts
CHANGED
|
@@ -23,9 +23,13 @@ export declare const DIARY_PREVIEW_LENGTH = 160;
|
|
|
23
23
|
export declare const MAX_TEXT_TOKENS = 400;
|
|
24
24
|
/**
|
|
25
25
|
* Compute the diary object key for a date.
|
|
26
|
-
* new Date(
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* diaryKey(new Date()) → today's key in the caller's LOCAL timezone
|
|
27
|
+
* diaryKey("2026-06-15") → "diary/2026/06/20260615.md" (literal Y-M-D)
|
|
28
|
+
*
|
|
29
|
+
* A `Date` is read with LOCAL components so "today" is the caller's wall-clock
|
|
30
|
+
* day (not the UTC day, which is a day ahead for users west of UTC in the
|
|
31
|
+
* evening). A `YYYY-MM-DD` string (e.g. from <input type="date">) is taken
|
|
32
|
+
* literally so the date round-trips exactly with no timezone shift.
|
|
29
33
|
*/
|
|
30
34
|
export declare const diaryKey: (date: Date | string) => string;
|
|
31
35
|
/** True when an id/key is a diary entry object. */
|
package/lib/utils/diary.js
CHANGED
|
@@ -24,19 +24,42 @@ export const MAX_TEXT_TOKENS = 400;
|
|
|
24
24
|
const pad2 = (n) => String(n).padStart(2, "0");
|
|
25
25
|
/**
|
|
26
26
|
* Compute the diary object key for a date.
|
|
27
|
-
* new Date(
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* diaryKey(new Date()) → today's key in the caller's LOCAL timezone
|
|
28
|
+
* diaryKey("2026-06-15") → "diary/2026/06/20260615.md" (literal Y-M-D)
|
|
29
|
+
*
|
|
30
|
+
* A `Date` is read with LOCAL components so "today" is the caller's wall-clock
|
|
31
|
+
* day (not the UTC day, which is a day ahead for users west of UTC in the
|
|
32
|
+
* evening). A `YYYY-MM-DD` string (e.g. from <input type="date">) is taken
|
|
33
|
+
* literally so the date round-trips exactly with no timezone shift.
|
|
30
34
|
*/
|
|
31
35
|
export const diaryKey = (date) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
let y;
|
|
37
|
+
let m;
|
|
38
|
+
let day;
|
|
39
|
+
if (typeof date === "string") {
|
|
40
|
+
const lit = /^(\d{4})-(\d{2})-(\d{2})/.exec(date);
|
|
41
|
+
if (lit) {
|
|
42
|
+
y = Number(lit[1]);
|
|
43
|
+
m = Number(lit[2]);
|
|
44
|
+
day = Number(lit[3]);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const d = new Date(date);
|
|
48
|
+
if (isNaN(d.getTime()))
|
|
49
|
+
throw new Error(`diaryKey: invalid date "${date}"`);
|
|
50
|
+
y = d.getFullYear();
|
|
51
|
+
m = d.getMonth() + 1;
|
|
52
|
+
day = d.getDate();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
if (isNaN(date.getTime()))
|
|
57
|
+
throw new Error("diaryKey: invalid Date");
|
|
58
|
+
y = date.getFullYear();
|
|
59
|
+
m = date.getMonth() + 1;
|
|
60
|
+
day = date.getDate();
|
|
35
61
|
}
|
|
36
|
-
|
|
37
|
-
const m = pad2(d.getUTCMonth() + 1);
|
|
38
|
-
const day = pad2(d.getUTCDate());
|
|
39
|
-
return `${DIARY_PREFIX}${y}/${m}/${y}${m}${day}.md`;
|
|
62
|
+
return `${DIARY_PREFIX}${y}/${pad2(m)}/${y}${pad2(m)}${pad2(day)}.md`;
|
|
40
63
|
};
|
|
41
64
|
/** True when an id/key is a diary entry object. */
|
|
42
65
|
export const isDiaryKey = (key) => key.startsWith(DIARY_PREFIX) && key.endsWith(".md");
|