-
Notifications
You must be signed in to change notification settings - Fork 17
Show torrent fields: creation_date, created_by, encoding #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josecelano
merged 6 commits into
torrust:develop
from
mario-nt:#278-show-torrent-fields-creation_date-created-by-encoding
Dec 26, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
56af742
feat: [#278] show torrent fields creation date created by encoding
3f09085
refactor: [#297] Creation date now display as UTC
mario-nt 5bad420
refactor: [#297] added error checks
mario-nt e4772ae
refactor: [#297] new error checks and refactoring
mario-nt 489da9d
refactor: [#297] refactored error control
mario-nt 4281526
refactor: [#297] code cleanup
mario-nt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <template> | ||
| <div id="torrent-created-by" class="flex flex-col gap-6"> | ||
| <div class="flex flex-row items-center justify-between"> | ||
| <h2 class="mr-1 text-2xl font-medium text-left text-neutral-content/50"> | ||
| Created by | ||
| </h2> | ||
| <button | ||
| class="flex flex-col items-center justify-center w-10 h-10 duration-200 bg-transparent text-base-content/50 hover:text-base-content rounded-xl" | ||
| @click="collapsed = !collapsed" | ||
| > | ||
| <ChevronDownIcon class="w-6" :class="{ 'rotate-90': collapsed }" /> | ||
| </button> | ||
| </div> | ||
| <template v-if="!collapsed"> | ||
| <div class="flex flex-col w-full h-full p-6 grow bg-base-100 rounded-2xl"> | ||
| <template v-if="torrent.created_by"> | ||
| <Markdown :source="torrent.created_by" /> | ||
| </template> | ||
| <template v-else> | ||
| <span class="italic text-neutral-content">No created by field provided.</span> | ||
| </template> | ||
| </div> | ||
| </template> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { ChevronDownIcon } from "@heroicons/vue/24/solid"; | ||
| import { TorrentResponse } from "torrust-index-types-lib"; | ||
| import { PropType } from "vue"; | ||
| import { ref } from "#imports"; | ||
| import Markdown from "~/components/Markdown.vue"; | ||
|
|
||
| const collapsed = ref(false); | ||
|
|
||
| const props = defineProps({ | ||
| torrent: { | ||
| type: Object as PropType<TorrentResponse>, | ||
| required: true | ||
| } | ||
| }); | ||
| </script> | ||
|
|
||
| <style scoped> | ||
|
|
||
| </style> |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <template> | ||
| <div id="torrent-creation-date" class="flex flex-col gap-6"> | ||
| <div class="flex flex-row items-center justify-between"> | ||
| <h2 class="mr-1 text-2xl font-medium text-left text-neutral-content/50"> | ||
| Creation Date | ||
| </h2> | ||
| <button | ||
| class="flex flex-col items-center justify-center w-10 h-10 duration-200 bg-transparent text-base-content/50 hover:text-base-content rounded-xl" | ||
| @click="collapsed = !collapsed" | ||
| > | ||
| <ChevronDownIcon class="w-6" :class="{ 'rotate-90': collapsed }" /> | ||
| </button> | ||
| </div> | ||
| <template v-if="!collapsed"> | ||
| <div class="flex flex-col w-full h-full p-6 grow bg-base-100 rounded-2xl"> | ||
| <template v-if="torrent.creation_date"> | ||
| {{ formatedDateFromTimestamp }} | ||
| </template> | ||
| <template v-else> | ||
| <span class="italic text-neutral-content">No creation date provided.</span> | ||
| </template> | ||
| </div> | ||
| </template> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { ChevronDownIcon } from "@heroicons/vue/24/solid"; | ||
| import { TorrentResponse } from "torrust-index-types-lib"; | ||
| import { PropType } from "vue"; | ||
| import { ref } from "#imports"; | ||
| import Markdown from "~/components/Markdown.vue"; | ||
| import { formatTimestamp } from "~/src/helpers/DateConverter"; | ||
|
|
||
| const collapsed = ref(false); | ||
|
|
||
| const props = defineProps({ | ||
| torrent: { | ||
| type: Object as PropType<TorrentResponse>, | ||
| required: true | ||
| } | ||
| }); | ||
|
|
||
| const formatedDateFromTimestamp = formatTimestamp(props.torrent.creation_date); | ||
|
|
||
| </script> | ||
|
|
||
| <style scoped> | ||
|
|
||
| </style> |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <template> | ||
| <div id="torrent-encoding" class="flex flex-col gap-6"> | ||
| <div class="flex flex-row items-center justify-between"> | ||
| <h2 class="mr-1 text-2xl font-medium text-left text-neutral-content/50"> | ||
| Encoding | ||
| </h2> | ||
| <button | ||
| class="flex flex-col items-center justify-center w-10 h-10 duration-200 bg-transparent text-base-content/50 hover:text-base-content rounded-xl" | ||
| @click="collapsed = !collapsed" | ||
| > | ||
| <ChevronDownIcon class="w-6" :class="{ 'rotate-90': collapsed }" /> | ||
| </button> | ||
| </div> | ||
| <template v-if="!collapsed"> | ||
| <div class="flex flex-col w-full h-full p-6 grow bg-base-100 rounded-2xl"> | ||
| <template v-if="torrent.encoding"> | ||
| <Markdown :source="torrent.encoding" /> | ||
| </template> | ||
| <template v-else> | ||
| <span class="italic text-neutral-content">No encoding provided.</span> | ||
| </template> | ||
| </div> | ||
| </template> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { ChevronDownIcon } from "@heroicons/vue/24/solid"; | ||
| import { TorrentResponse } from "torrust-index-types-lib"; | ||
| import { PropType } from "vue"; | ||
| import { ref } from "#imports"; | ||
| import Markdown from "~/components/Markdown.vue"; | ||
|
|
||
| const collapsed = ref(false); | ||
|
|
||
| const props = defineProps({ | ||
| torrent: { | ||
| type: Object as PropType<TorrentResponse>, | ||
| required: true | ||
| } | ||
| }); | ||
| </script> | ||
|
|
||
| <style scoped> | ||
|
|
||
| </style> |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| type UnixTimestamp = number; | ||
| type FormattedDate = string; | ||
|
|
||
| class InvalidDateError extends Error {} | ||
|
|
||
| /** | ||
| * Takes the date in seconds from Unix Epoch time and converts it to human readable format. | ||
| * | ||
| * For example: 1701688451 -> "Mon Dec 04 2023" | ||
| */ | ||
|
|
||
| export function formatTimestamp (creationDate: UnixTimestamp): FormattedDate | Error { | ||
| const milliseconds = creationDate * 1000; | ||
|
|
||
| const convertedDate = new Date(milliseconds); | ||
|
|
||
| return isNaN(convertedDate.valueOf()) | ||
| ? new InvalidDateError( | ||
| `Invalid date. Could not create a new date from timestamp value: ${creationDate}`) | ||
| : convertedDate.toDateString(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tests I did:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mario-nt I've just created another example.
Why do you want to differentiate between an invalid timestamp in the database and a timestamp greater than the maximum Date? Now we are showing the value causing the error so we can find out later what happened.