Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

feature: time formate

kruzhambusf9633834dbf6
diff --git a/src/marketplace/cdn/cdn.service.ts b/src/marketplace/cdn/cdn.service.ts
index d4079b1e6..82e1717ca 100644
--- a/src/marketplace/cdn/cdn.service.ts
+++ b/src/marketplace/cdn/cdn.service.ts
@@ -13,18 +13,10 @@ export class CdnService {
private readonly configService: ConfigService,
) {}
- async uploadFile(file: Express.Multer.File | Buffer, originalname?: string): Promise<{ filename: string }> {
+ async uploadFile(file: Express.Multer.File): Promise<{ filename: string }> {
try {
- let filePath
- if (file instanceof Buffer) {
- filePath = `${tmpdir()}/${originalname}`
- console.log(filePath)
- await writeFile(filePath, file)
- } else {
- filePath = `${tmpdir()}/${file.originalname}`
- await writeFile(filePath, file.buffer)
- }
- console.log('saved')
+ const filePath = `${tmpdir()}/${file.originalname}`
+ await writeFile(filePath, file.buffer)
const form = new FormData()
form.append('token', this.configService.get('CDN_ACCESS_TOKEN'))
@@ -42,26 +34,6 @@ export class CdnService {
}
}
- async uploadBuffer(buffer: Buffer, originalname: string): Promise<{ filename: string }> {
- try {
- const filePath = `${tmpdir()}/${originalname}`
-
- const form = new FormData()
- form.append('token', this.configService.get('CDN_ACCESS_TOKEN'))
- form.append('file', buffer, new Date().toISOString() + '.zip')
-
- const { data } = await this.httpService.axiosRef.post('file', form, {
- headers: {
- 'Content-Type': `multipart/form-data; boundary=${form.getBoundary()}`,
- },
- })
-
- return data
- } catch (error) {
- console.error(error)
- }
- }
-
async deleteFile(filename: string): Promise<void> {
try {
await this.httpService.axiosRef.delete(`file/${filename}`, {
diff --git a/src/project/dto/project.dto.ts b/src/project/dto/project.dto.ts
index ec00067e4..e80e4e971 100644
--- a/src/project/dto/project.dto.ts
+++ b/src/project/dto/project.dto.ts
@@ -46,10 +46,4 @@ export class ProjectDTO {
"When true, anyone on the internet (including Google) would be able to see the project's Dashboard.",
})
public: boolean
-
- @ApiProperty({
- required: false,
- description: 'Export data from the project',
- })
- exportData: boolean
}
diff --git a/src/project/project.controller.ts b/src/project/project.controller.ts
index d19cea298..3fbc5efe6 100644
--- a/src/project/project.controller.ts
+++ b/src/project/project.controller.ts
@@ -811,79 +811,4 @@ export class ProjectController {
await this.actionTokensService.delete(id)
}
}
-
- @Get('/export/:pid')
- @UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
- @Roles(UserType.CUSTOMER, UserType.ADMIN)
- @ApiResponse({ status: 200, type: Project })
- async exportProject(
- @Param('pid') pid: string,
- @Query() date: {
- from: string
- to: string
- },
- @CurrentUserId() uid: string,
- ): Promise<string> {
- this.logger.log({ uid, pid }, 'GET /project/export/:pid')
-
- let project = await this.projectService.findOne(pid, {
- relations: ['admin', 'share', 'share.user'],
- })
-
- if (_isEmpty(project)) {
- throw new NotFoundException(`Project with ID ${pid} does not exist`)
- }
-
- this.projectService.allowedToManage(project, uid, project.admin.roles)
-
- const fromDateTimestamp = dayjs(date.from).unix()
- const toDateTimestamp = dayjs(date.to).unix()
-
- const data = await clickhouse.query(
- `SELECT * FROM analytics WHERE created >= '${fromDateTimestamp}' AND created <= '${toDateTimestamp}' AND pid='${pid}' FORMAT CSVWithNames`,
- ).toPromise() as unknown
-
- const zip = new JSZip()
-
- Object.keys(data[0]).forEach((key) => {
- const csvDate = json2csv.parse(data, {
- fields: [key],
- })
- zip.file(`${key}.csv`, csvDate)
- console.log(key)
- })
-
- const zipData = await zip.generateAsync({ type: 'nodebuffer' })
-
- const { filename } = await this.cdnService.uploadBuffer(zipData, new Date().toLocaleString())
-
- // const zip = new JSZip();
-
- // const _data = zip.folder('data')
-
- // Object.keys(data[0]).forEach((key) => {
- // const csvData = json2csv.parse(data, {
- // fields: [key],
- // })
- // _data.file(`${key}.csv`, csvData)
- // console.log(key);
- // })
-
- // const zipData = await
-
- // const { filename } = await this.cdnService.uploadFile(zipData)
-
- project = {
- ...project,
- exportData: {
- filename,
- createdAt: new Date(),
- }
- }
-
- await this.projectService.create(project)
-
- return filename
- }
}
diff --git a/src/task-manager/task-manager.service.ts b/src/task-manager/task-manager.service.ts
index 3cdadce47..c79d83523 100644
--- a/src/task-manager/task-manager.service.ts
+++ b/src/task-manager/task-manager.service.ts
@@ -489,28 +489,4 @@ export class TaskManagerService {
}
}
}
-
- @Cron(CronExpression.EVERY_HOUR)
- async checkProjects(): Promise<void> {
- const projects = await this.projectService.findWhere({
- active: true,
- })
-
- for (let i = 0; i < _size(projects); ++i) {
- const project = projects[i]
-
- if (project?.exportData?.filename) {
- const { createdAt } = project.exportData
- const now = new Date()
-
- if (now.getTime() - createdAt.getTime() > 24 * 60 * 60 * 1000) {
- await this.projectService.update(project.id, {
- ...project,
- exportData: null,
- })
- }
- }
- }
- }
-
}
diff --git a/src/user/entities/user.entity.ts b/src/user/entities/user.entity.ts
index 8741185bf..41a8774db 100644
--- a/src/user/entities/user.entity.ts
+++ b/src/user/entities/user.entity.ts
@@ -78,6 +78,11 @@ export enum Theme {
christmas = 'christmas',
}
+export enum TimeFormat {
+ '12-hour' = '12-hour',
+ '24-hour' = '24-hour',
+}
+
export const MAX_EMAIL_REQUESTS = 4 // 1 confirmation email on sign up + 3 additional ones
export const DEFAULT_TIMEZONE = 'Etc/GMT'
@@ -221,4 +226,11 @@ export class User {
@OneToMany(() => Complaint, complaint => complaint.user)
@JoinTable()
complaints: Complaint[]
+
+ @Column({
+ type: 'enum',
+ enum: TimeFormat,
+ default: TimeFormat['12-hour'],
+ })
+ timeFormat: TimeFormat
}
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index e7fe293ed..e661a39c7 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -37,6 +37,7 @@ import {
MAX_EMAIL_REQUESTS,
PlanCode,
Theme,
+ TimeFormat,
} from './entities/user.entity'
import { Roles } from '../common/decorators/roles.decorator'
import { Pagination } from '../common/pagination/pagination'
@@ -89,7 +90,6 @@ export class UserController {
return await this.userService.paginate({ take, skip })
}
- // set theme
@Put('/theme')
@UseGuards(RolesGuard)
@UseGuards(SelfhostedGuard)
@@ -592,4 +592,22 @@ export class UserController {
return user
}
+
+ @Put('/change-time-format')
+ @UseGuards(RolesGuard)
+ @UseGuards(SelfhostedGuard)
+ @Roles(UserType.CUSTOMER, UserType.ADMIN)
+ async changeTimeFormat(
+ @CurrentUserId() userId: string,
+ @Body('timeFormat') timeFormat: TimeFormat,
+ ): Promise<User> {
+ this.logger.log({ userId, timeFormat }, 'PUT /user/change-time-format')
+ const user = await this.userService.findOneWhere({ id: userId })
+ if (user.timeFormat === timeFormat) {
+ throw new BadRequestException('Time format is already set to this value')
+ }
+
+ await this.userService.update(userId, { timeFormat })
+ return this.userService.omitSensitiveData(user)
+ }
}