GiovanH / unofficial-homestuck-collection

An offline collection of Homestuck and its related works.
GNU General Public License v3.0
25 stars 3 forks source link

story_id is user-input, needs to be error checked #107

Closed github-actions[bot] closed 3 years ago

github-actions[bot] commented 3 years ago

story_id is user-input, needs to be error checked

https://github.com/Bambosh/unofficial-homestuck-collection/blob/611ca34fe82644796c901f114e6b35b6db08472b/src/components/SystemPages/Log.vue#L121

      sort: 'log',
      sortNames: {
        asc: 'oldest to newest',
        desc: 'newest to oldest'
      }
    }
  },
  computed: {
    storyId(){
      if (!this.routeParams.mode) {
        // We are on the root page
        return undefined
      }

      // TODO: Replace character splicing with something actually resembling parsing
      let story = this.routeParams.mode.charAt(0)
      if (story == "r")
        story = "ryanquest"

      return story
    },
    log() {
      // depends on
      // this.$localData.settings.newReader;

      // A sorted list of log objects
      if (!this.storyId) 
        return undefined

      return this.storyLogRaw(this.storyId).filter(page => 
        !this.$pageIsSpoiler(page.page_num)
      ).sort(this.sorter)
    },
    reverseLink(){
      return /^\d_asc$/.test(this.routeParams.mode) ? `/log/${this.routeParams.mode.charAt(0)}` : `/log/${this.routeParams.mode}_asc`
    },
    reverseText(){
      // Todo
      return "View " + (this.sortNames[this.sortOrderNext] || "log")
    },
    sortOrderNext(){
      let next = (this.sortOrder == 'desc' ? 'asc' : 'desc')
      return next
    },
    sortOrder(){
      // The text key that defines the sort order
      if (!this.routeParams.mode)
        // Sort order w/o selected log???
        return undefined

      let sort_order = /^\d_asc$/.test(this.routeParams.mode) ? 'asc' : 'desc'
      return sort_order
    },
    sorter(){
      // The sorter function that .sort() keys
      let default_="asc"
      return sort_methods[this.sortOrder] || sort_methods[default_]
    },
    storyLogRaw() {
      // The unsorted story log
      this.$archive;

      // console.log("Recalculating raw story log memo")
      // Vue should really be able to keep track of this, but it just can't. 
      // TODO: story_id is user-input, needs to be error checked

      return this.memoized(story_id => {
        // console.log("Recalculating raw story log (BAD)")

        return this.$getAllPagesInStory(story_id).map(page_num => 
          this.getLogEntry(story_id, page_num)
        )
      }, "storyLogRaw", 10)
    }
  },
  methods: {
    getLogEntry(story_id, page_num) {
      // Returns the actual entry object for a given page
      // needs the story_id because ryanquest

      // TODO: Memoize this?
      let story = (story_id == "ryanquest" ? this.$archive.mspa.ryanquest : this.$archive.mspa.story)
      let page = story[page_num];
      let page_type = (story_id == "ryanquest" ? "ryanquest" : "mspa")
ndex 0cb3d28..3ebe45b 100644
++ b/src/components/SystemPages/Settings.vue

146f545dd5a6d57fd2449fb4272466709264a10f

GiovanH commented 3 years ago

Resolved with d8891ff3ce8a1399d190a71feca844bd38523ce6