Skip to content

Commit

Permalink
fix file based import
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed Mar 27, 2024
1 parent 9f11a73 commit 9bd7bdf
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
17 changes: 12 additions & 5 deletions src/imports/background/data-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
startOfDay,
WEEK_IN_MS,
} from '@worldbrain/memex-common/lib/utils/date-time'
import { parseHTML } from 'linkedom/worker'

export default class ImportDataSources {
static LOOKBACK_WEEKS = 12 // Browser history is limited to the last 3 months
Expand Down Expand Up @@ -116,11 +117,17 @@ export default class ImportDataSources {
allowTypes[TYPE.OTHERS] === SERVICES.POCKET ||
allowTypes[TYPE.OTHERS] === SERVICES.NETSCAPE
) {
contents = await loadBlob({
url,
timeout: 10000,
responseType: 'document',
})
if (url.startsWith('data:text/html;base64,')) {
const base64Content = url.split('data:text/html;base64,')[1]
const htmlContent = atob(base64Content)
contents = parseHTML(htmlContent).document
} else {
contents = await loadBlob({
url,
timeout: 10000,
responseType: 'document',
})
}
}

if (allowTypes[TYPE.OTHERS] === SERVICES.POCKET) {
Expand Down
1 change: 0 additions & 1 deletion src/imports/background/service-parsers/netscape-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const parseShallowList: ServiceParser = (doc) => {
),
)
for (let header of headers) {
console.log(header)
const collectionName =
header.textContent !== ''
? header.textContent
Expand Down
12 changes: 9 additions & 3 deletions src/options/imports/container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,19 @@ class ImportContainer extends Component {

handleInputFile = (event) => {
const input = event.target

if (!input.files[0]) {
return
}
const file = input.files[0]
this.props.boundActions.prepareImport()
this.props.boundActions.setBlobUrl(URL.createObjectURL(file))
setTimeout(() => this.props.recalcEsts(), 500)

const reader = new FileReader()
reader.onloadend = () => {
this.props.boundActions.setBlobUrl(reader.result)
}
reader.readAsDataURL(file)

setTimeout(() => this.props.recalcEsts(), 3000)
}

renderCancelButton() {
Expand Down
2 changes: 1 addition & 1 deletion src/options/imports/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const finishImportsReducer = ({ loading = false, finish = true }) => (
const prepareImportReducer = (state) => {
return {
...state,
importStatus: STATUS.LOADING,
// importStatus: STATUS.LOADING,
loadingMsg: 'Calculating size of history & bookmarks',
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/page-indexing/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,13 +930,15 @@ export class PageIndexingBackground {
content = pageData.content
htmlBody = pageData.htmlBody
favIconURI = pageData.favIconURI
// title = pageData.title ?? props.metaData?.pageTitle

await this.storeDocContent(normalizeUrl(props.fullUrl), {
htmlBody,
})

pageDoc.favIconURI = favIconURI
pageDoc.content.title = content?.title || props.metaData?.pageTitle

pageDoc.content.fullText = content?.fullText
} else {
const pdfData = await this.options.fetchPdfData(props.fullUrl)
Expand Down

0 comments on commit 9bd7bdf

Please sign in to comment.