Skip to content

Commit 1145236

Browse files
authored
Merge pull request #152 from import-ai/fix/assets_name
fix: improve asset name handling and add timestamps to resource DTOs
2 parents 49c2adb + f53da8f commit 1145236

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "omniboxd",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"private": true,
55
"scripts": {
66
"build": "nest build",

src/resources/dto/resource.dto.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export class ResourceMetaDto {
1414
resource_type: string;
1515
attrs: Record<string, any>;
1616
tags: TagDto[];
17+
created_at: string;
18+
updated_at: string;
1719

1820
static fromEntity(resource: Resource, tags: TagDto[] = []) {
1921
const dto = new ResourceMetaDto();
@@ -23,6 +25,8 @@ export class ResourceMetaDto {
2325
dto.resource_type = resource.resourceType;
2426
dto.attrs = resource.attrs;
2527
dto.tags = tags;
28+
dto.created_at = resource.createdAt.toISOString();
29+
dto.updated_at = resource.updatedAt.toISOString();
2630
return dto;
2731
}
2832
}
@@ -40,6 +44,8 @@ export class ResourceDto {
4044
current_permission: ResourcePermission;
4145
path: ResourceMetaDto[];
4246
space_type: SpaceType;
47+
created_at: string;
48+
updated_at: string;
4349

4450
static fromEntity(
4551
resource: Resource,
@@ -61,6 +67,8 @@ export class ResourceDto {
6167
dto.current_permission = currentPermission;
6268
dto.path = path;
6369
dto.space_type = spaceType;
70+
dto.created_at = resource.createdAt.toISOString();
71+
dto.updated_at = resource.updatedAt.toISOString();
6472
return dto;
6573
}
6674
}

src/resources/file-resources.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const uploadLanguageDatasets = [
1313
{ filename: '🚀🔥.txt', content: '😊👍🌍' },
1414
];
1515

16-
describe('ResourcesController (e2e)', () => {
16+
describe('FileResourcesController (e2e)', () => {
1717
let client: TestClient;
1818

1919
beforeAll(async () => {

src/resources/resources.e2e-spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,16 @@ describe('ResourcesController (e2e)', () => {
677677
expect(childResource).toBeDefined();
678678
expect(childResource.name).toBe('Child Resource for List');
679679
expect(childResource.attrs).toEqual(childAttrs);
680+
681+
// Check for required timestamp fields
682+
expect(childResource).toHaveProperty('created_at');
683+
expect(childResource).toHaveProperty('updated_at');
684+
expect(childResource.created_at).toMatch(
685+
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/,
686+
);
687+
expect(childResource.updated_at).toMatch(
688+
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/,
689+
);
680690
});
681691

682692
it('should return empty array for resource with no children', async () => {

src/resources/resources.service.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export class ResourcesService {
149149
'name',
150150
'attrs',
151151
'parentId',
152+
'createdAt',
152153
'updatedAt',
153154
'namespaceId',
154155
'resourceType',
@@ -331,6 +332,7 @@ export class ResourcesService {
331332
'name',
332333
'attrs',
333334
'parentId',
335+
'createdAt',
334336
'updatedAt',
335337
'namespaceId',
336338
'resourceType',
@@ -459,7 +461,16 @@ export class ResourcesService {
459461
}
460462

461463
const children = await this.resourceRepository.find({
462-
select: ['id', 'name', 'parentId', 'resourceType', 'attrs', 'tagIds'],
464+
select: [
465+
'id',
466+
'name',
467+
'parentId',
468+
'resourceType',
469+
'attrs',
470+
'tagIds',
471+
'createdAt',
472+
'updatedAt',
473+
],
463474
where: {
464475
namespaceId,
465476
parentId: resourceId,
@@ -574,7 +585,15 @@ export class ResourcesService {
574585
while (true) {
575586
const resource = await this.resourceRepository.findOne({
576587
where: { namespaceId, id: resourceId },
577-
select: ['id', 'name', 'resourceType', 'parentId', 'globalPermission'],
588+
select: [
589+
'id',
590+
'name',
591+
'resourceType',
592+
'parentId',
593+
'globalPermission',
594+
'createdAt',
595+
'updatedAt',
596+
],
578597
});
579598
if (!resource) {
580599
throw new NotFoundException('Resource not found');
@@ -698,7 +717,8 @@ export class ResourcesService {
698717
parentId?: string,
699718
resourceId?: string,
700719
) {
701-
const originalName = encodeFileName(fileName);
720+
const originalName = getOriginalFileName(fileName);
721+
const encodedName = encodeFileName(fileName);
702722
let resource: Resource;
703723
if (resourceId) {
704724
resource = await this.get(resourceId);
@@ -713,6 +733,7 @@ export class ResourcesService {
713733
parentId,
714734
attrs: {
715735
original_name: originalName,
736+
encoded_name: encodedName,
716737
mimetype: mimetype,
717738
},
718739
});

0 commit comments

Comments
 (0)