-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: download the data functionality done
- Loading branch information
Showing
7 changed files
with
152 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,68 @@ | ||
import { RedirectToLogin } from '../common/index.js'; | ||
import {RedirectToLogin, SaveFile} from '../common/index.js'; | ||
|
||
export function DeleteAccountModelInit() { | ||
const deleteBtn = document.querySelector('#delete-my-account'); | ||
if (!deleteBtn) { | ||
return; | ||
} | ||
const deleteModal = document.querySelector('#delete-account-modal'); | ||
deleteBtn.addEventListener('click', (e) => { | ||
deleteModal.classList.toggle('hidden'); | ||
}); | ||
const deleteBtn = document.querySelector('#delete-my-account'); | ||
if (!deleteBtn) { | ||
return; | ||
} | ||
const deleteModal = document.querySelector('#delete-account-modal'); | ||
deleteBtn.addEventListener('click', (e) => { | ||
deleteModal.classList.toggle('hidden'); | ||
}); | ||
} | ||
|
||
async function DisableAccount() { | ||
const url = '/setting/disablemyaccount'; | ||
try { | ||
const response = await fetch(url, { method: 'PUT' }); | ||
if (!response.ok) { | ||
throw new Error(`Response status: ${response.status}`); | ||
} | ||
return await response.json(); | ||
} catch (error) { | ||
console.error(error.message); | ||
} | ||
const url = '/setting/disablemyaccount'; | ||
try { | ||
const response = await fetch(url, {method: 'PUT'}); | ||
if (!response.ok) { | ||
throw new Error(`Response status: ${response.status}`); | ||
} | ||
return await response.json(); | ||
} catch (error) { | ||
console.error(error.message); | ||
} | ||
} | ||
|
||
export function DisableMyAccountInit() { | ||
const disableBtn = document.querySelector('#disable-my-account'); | ||
if (!disableBtn) { | ||
return; | ||
} | ||
disableBtn.addEventListener('click', async (e) => { | ||
console.info('Disable my account event'); | ||
const res = await DisableAccount(); | ||
if (res && res?.Status === 'OK') { | ||
console.info('Account is disabled until you logged in back.'); | ||
RedirectToLogin(); | ||
} | ||
}); | ||
const disableBtn = document.querySelector('#disable-my-account'); | ||
if (!disableBtn) { | ||
return; | ||
} | ||
disableBtn.addEventListener('click', async (e) => { | ||
console.info('Disable my account event'); | ||
const res = await DisableAccount(); | ||
if (res && res?.Status === 'OK') { | ||
console.info('Account is disabled until you logged in back.'); | ||
RedirectToLogin(); | ||
} | ||
}); | ||
} | ||
|
||
export function DownloadMyData() { | ||
const download = document.querySelectorAll('#download'); | ||
if (!download.length) { | ||
return; | ||
} | ||
download.forEach(d => { | ||
d.addEventListener('click', async (e) => { | ||
if (!e.target.dataset?.format.length) { | ||
return | ||
} | ||
const url = `/setting/downloadmydata/${e.target.dataset?.format}`; | ||
try { | ||
const headers = new Headers(); | ||
headers.append('Content-Type', 'application/json'); | ||
|
||
const response = await fetch(url, {method: 'GET', headers: headers}); | ||
if (!response.ok) { | ||
throw new Error(`Response status: ${response.status}`); | ||
} | ||
const jData = await response.json(); | ||
SaveFile(`pinmyblogs.${e.target.dataset?.format}`, jData, e.target.dataset?.format); | ||
} catch (error) { | ||
console.error(error.message); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
package models | ||
|
||
import "gorm.io/gorm" | ||
import ( | ||
"database/sql" | ||
"gorm.io/gorm" | ||
"time" | ||
) | ||
|
||
type DeletedAt sql.NullTime | ||
type Url struct { | ||
gorm.Model | ||
WebLink string | ||
IsActive bool | ||
IsDeleted bool | ||
CreatedBy string `gorm:"index;size:255;not null"` | ||
Comment string | ||
Summary string | ||
Title string | ||
Tag string | ||
IsFav bool | ||
IsArchived bool | ||
Category string | ||
IsBookMarked bool | ||
ID uint `gorm:"primarykey" json:"id"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
UpdatedAt time.Time `json:"updatedAt"` | ||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` | ||
WebLink string `json:"webLink"` | ||
IsActive bool `json:"-"` | ||
IsDeleted bool `json:"isDeleted"` | ||
CreatedBy string `gorm:"index;size:255;not null" json:"createdBy"` | ||
Comment string `json:"-"` | ||
Summary string `json:"summary"` | ||
Title string `json:"title"` | ||
Tag string `json:"tag"` | ||
IsFav bool `json:"isFav"` | ||
IsArchived bool `json:"isArchived"` | ||
Category string `json:"-"` | ||
IsBookMarked bool `json:"isBookMarked"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters